Tokens in Python: A) B) C) D) E)
Tokens in Python: A) B) C) D) E)
Tokens in Python: A) B) C) D) E)
Syntax:
print(arguments)
Note: The argument of the print function can be a value of any
type int, str, float etc.
Example:
>>>print('Welcome to Python')
Welcome to Python
>>> a = 10
>>> print(a)
10
Assigning Values to a Variable
Assigning value to a variable is called an assignment
statement.
Syntax:
Variable = Expression
Example:
>>> a = 10
>>> a
>>> 10
>>> str = ‘Hello’
>>> str
>>> ‘Hello’
Multiple Assignments
Python supports simultaneous assignment to
multiple variables.
Syntax:
Var1,Var2, Var3…. = Exp1, Exp2, Exp3…
>>> P , Q = 10, 20
>>> p
10
>>> Q
>>> 20
The input() function
It is used to accept an input from a user.
Syntax:
Variable_Name = input()
OR
Variable_Name = input(‘String’)
Example:
>>> str1 = input('Please Enter the String:')
Please Enter the String:amit
>>> print(str1)
amit
FORMATTING NUMBER AND
STRINGS
A formatting string helps make string look presentable to the user for
printing.
Syntax:
format(item, format-specifier)
Where,
- item is the number or string
- format-specifier is a string that specifies how the item is
formatted
Example:
>>> z= 12.345
>>> z
12.345
>>> format(z,'.2f')
'12.35'
Python Various inbuilt function
Name of Function Meaning Example:
max(x1,x2, x3,…….XN) Returns Largest >>>max(10,20,30)
among X1, X2, >>>30
…..XN
min(x1,x2, x3,…….XN) Returns smallest >>>min(10,20,30)
among X1, X2, >>>30
…..XN
abs(x) Returns absolute >>>abs(-10)
value of x >>>10
>>>abs(4)
4
pow(X,Y) Returns XY >>>pow(2,3)
8
Round(x) Return the value >>> round(10.23)
nearest to the 10
value of x >>> round(10.90)
11
List of Function under math Module
Name of Meaning Example:
Function
Round X to nearest integer and >>>import math
ceil(X) returns that integer. >>> math.ceil(10.23)
11
floor(X) Returns the largest value not greater >>>import math
than X >>> math.floor(18.9)
18
exp(X) Returns the exponential value for ex >>>import math
>>> math.exp(1)
2.718281828459045