Professional Documents
Culture Documents
FUNDAMENTALS OF
PYTHON
Lecture#2
Course Outline/Intro,
Data Types, Functions, Print, Input
Basic Programs.
1. print(“Hi”,end=‘’)
2. Print(“how are you”)
1. print(“Hi”,end=‘*’)
2. Print(“how are you”)
Formatting with Print() Function
•Examples: Try following
1. print(“hi”, “how” , “are” , “you” , sep=‘*’)
2. print(“hi”, “how” , “are” , “you” , sep=‘\n’)
Your first programs!
Your first programs
1. x=3
2. print(“value of x is: ”)
3. print(x)
1. x=3
2. print(“value of x is: ” , x)
1. x=int(“3.9”)
2. print(“value of x is: ” , x)
Your first programs
1. x=str(3)
2. print(“value of x is: ”)
3. print(x)
1. x=‘3’
2. print(“value of x is: ” , x)
Your first programs
1. x=3
2. y=4
3. print(“value of x is ” , x, “and y is” , y)
1. x=3
2. y=4
3. print(“value of x is ” , x, “and y is” , y)
Input() function
Input() function
• This function prompts user to enter value
• Remember input() function takes string by
default.
• You need to change data type to take integer
value.
Input() function
1. x=input(“enter value”)
2. print(x)
1. x=int(input(“enter value”))
2. print(x)
Mathematics With
Python
Mathematics With Python
• You can perform all arithmetic operation with
python.
OPERATOR SYMBOL OPERATION
Addition + Adds values
Subtraction - Subtract Values
Division / Divide Values,
result in float.
Remainder % Gives remainder
after division
Division Without // Integer Divisional
Float Operator
Mathematics With Python
Remember:
1. Division operation always return answer in
float
2. Remainder depends whether input values are
float or integer.
Basic Programs
Basic Programs
1. x=3
2. y=4
3. z=x+y
4. print(z)
1. x=“3”
2. y=“4”
3. z=x+y
4. print(z)
Remember!
• Float + integer=Float
• String + float=illegal
1. x=4
2. y=5
3. z=x/y
4. print(z)
Concatenation
Concatenation
• The + (plus) sign, when applied to two strings,
becomes a concatenation operator .
1. x=4
2. y=“5”
3. z=x+y
4. print(z)