(toc) #title=(Table of Contact)
Basic Syntax Function
· 1) Print(): This function is used to print the values in python
print(“Hello”)
print(123)
Output= Hello Output=123
· 2) Type(): This function is used to
check the datatype of variable
A=”Hello”
B=123
print(type(a))
print(type(B))
Output= <class ‘str’>
Output=<class ‘int’>
· 3) Input(): This function is used to
take input from user at runtime
input(“Enter the value of A : ”)
print(“A : ”, a)
Output = Enter the value of A :
Hello #enter
A : Hello
· 4) Datetime(): This functions is used to
check the date and time of system
Comments in Python
·
Comments is used in python to make
readable
·
Comments make code easy to understand
for anyone
·
Comments are also when code testing
is going
·
Comments represented by # in
python
Type
of Comments
·
Single Line Comments
·
Multi Line Comments
Keywords
·
Keyword are the reserved words in Python. We cannot
use a keyword as a variable name, function name or any other identifier.
·
help(“keywords”)
Output= print all keywords table
in python
·
False Await Else
Import Pass None
Break Excepts In
Raise True Class
Finally Is Return
And Continue For
Lambda Try As
Def From Nonlocal
While Assert Del
Global Not With
Async Elif If
Or Yield
Data Type in Python
·
Data types are used before the variable to know which
type of values are stored in variable.
·
Data types are actually classes and variables are
instance(object) of these classes.
·
Following are the python’s built-in data type.
1. Numeric –
Integer(1), Float(1.1), Complex Number(1+2j)
A=1
print(type(A))
Output= <class ‘int’>
2. Sequence Type –
#List
#String
#Tuple
l= [1,2,3] s=
“Python”
t=(1,2,3)
print(type(l))
print(type(s))
print(type(t))
Output= <class
‘list’> Output=<class
‘str’> Output=<class
‘tuple’>
3. Boolean – True,
False
A=True
print(type(A))
Output=<class ‘bool’>
4. Set
5. Dictionary
A= {‘a’ , ‘b’ , ‘c’}
A= {‘Key’ , ‘Value’}
print(type(A))
print(type(A))
Output= <class ‘set’>
Output=<class ‘dict’>
Variables
·
Variables are names to store some values.
·
It can store integers, float, string, Boolean, set,
tuple, list and dictionary.
·
Rules of Variables:
-
Variable should start with Alphabet only.
-
Variable name should not have whitespaces.
-
We cannot use datatype name as a variable name.
-
Variable name are significant.
·
Python allow multiple variable at a time. -
eg: x, y= “Hello” “Word”
·
Python allow you to concat the variable using + (add)
sign.
·
Printing variables
-
get input from user
-
Uses of print function
·
Type conversion
a= int(input(“Enter the value of A :”) Output= Enter the
value A: 10
print(“A: ” a)
A: 10
print(type(a))
<class ‘int’>
Operator
·
Operators are used to perform operations on variable
and values in python.
·
Types of Operators:
1) Arithmetic
operators- Addition, Subtraction, Multiplication, Division, Modulus
2) Assignment
operators =, +=, -=, /=, <<=, >>=, &=, ^=, |=
3) Comparison
operators- Less than, Greater than, Equal, Not equal,
4) Logical operators-
And, Or, Not
5) Membership
operators- In, In not
6) Identity operators-
Is, Is not