Python
Python
Datatypes:- it is collection of various datatypes, describes what type of data we are storing in variable.
1.Numerical- int, float, complex(imaginary no. – 5j)
2.Sequential - collection of elements stored in variable-
list (collection of elements enclosed in [ separated with , ]) duplicate values allowed, mixed datatypes allowed, It is mutable it can be changed
string collection of characters enclosed in ‘ ‘,“ ”,’ ‘ ‘(multiline) , it is immutable cannot be changed
tuple in (,)- collection of datatypes enclosed in separated by (,). It is immutable used when data is not going to change (if want to change data convert it to list)
3.Set - collection of unordered elements inside {,}, allows mixed elements, doesn’t allows duplicates, immutable, do not have fixed memory allocation
4.Dictionary (collection of elements inside {,} but in key value pair, accessing elements through what the key is assigned, mutable(allows editing outside the OG indexing),
duplicates- values can be allowed to be same but keys must be not same
5.Boolean – (o/p in form of true or false)
Tuple methods –
count()-counts the occurrence of elements how many times it has written
index()- count at what posn the element Is located, two argument first which element second after what u want to search
Set Methods-
add()- we can add new elements in existing set
update()- we can join or update two or more sets means concatenate
Operators – these are the special symbols which perform operations on values or variables
There are 7 types of operators
1.Arithmetic (+ , - , * , / , // , ** ,%)
Division (/) - it will give floating point number Quotient as output
Floor division (//) – it will give the integer part of Quotient as output
Exponential (**) – it will give exponential value of a number
Modulus (%) - it will give remainder give as output
2. Relational – mostly used for comparison (==, <=, >=, <, >, !=)
3. Logical (and, or, not)
4. Bitwise
5. Assignment (=, +=, -=, *=, /=)
6. Membership – used to check whether the value taken is present in sequence or not (in, not in)
7. Identity- it compares the memory location/address of both object (is, is not)
Conditional statements – it is a statement which helps to execute a block of code based on condition applied.
Indentation space place vital role in conditional statements, that is space after certain conditional statement
1. if statement-
2. if else
3. if elif else
4. nested if else
2.while loop- It executes set of code multiple times till the condition satisfies
Syntax:
initialization/Start
while(condition):
#block of code
increment/decrement
Function- It is a block od code which performs a particular task,and is executed only when it is called. Initial letter compulsory capital.
Syntax:
Def function_name():
#block of code
return expression/value/variable
#function call
function_name
pass keyword- it allows to keep the function empty. The pass statement is used as a placeholder for future code.
Types of Arguments:-
1.Positional Arguments- Order must be followed by argument as per the parameters
2.Keyword Argument- Assigning parameter and argument like key and value pairs. In any order
3.Default Argument- In it directly parameters are assigned with values (compulsory it must be assigned at the end)
4.Variable length-
*args(arguments)- it is returns value in tuple
**kwargs(keyword arguments)- returns value in dictionary