Notes and some extra tips,tricks ,points ,suggestion etc

 VERSION == PY --VERSION

"," inbetween variables gets printed as single space

print(sep="abj") // single space will be replaced by abj

print(end="axn") // after printing axn will be added in the end without any space inbetween

escape sequence /t (tab space) /n (new line)

module installation == py -m pip install <<module name>>

comments - #  , """   """

By default the input is taken as string

reserved words == help("keywords")

alt+p previous command

In shell if we directly type something within " " then it as whole will be displayed .(known as display)

translator -- interpreter(line by line)=shell/interactive mode , compiler(whole program)=Script mode

GUI Programming uses tkinter library

"{index}".format(variable) will work same as variable in between text without multiple commas and inverted commas.   

import random 

x=5,y=5 then id(x)==id(y)

Data type : Conplex:

x=complex(2+5j)

x=2+5j # print(x.real,x.imag)

alternate to .format == f before" without space or , and {variablename}

bool(0)==false , else everything true

""" docstring """

extensions .py .pyw

math.floor(75/12)==6

"k"+"t"==kt concatenation (no spaces)

replication "kt"*2 == ktkt (no spaces)

not equal !=,   <>(doesn't work)

string comparison is base don ascii value and is from left to right

eval("15+12")==27(int)

py  help("modules")

sequel flow==construct

range(start,stop,step)

str[index] interpreter == quotes will come

display method give answers in single quotes

"abc"*7=== 7*"abc"

7*[1,2,3],7*(1,2,3) is valid

7*{1:'b'} is invalid (keys are immutable,values are mutable)

immutable-string,tuple,Frozenset,numeric... (we can't change the value in place)

When using comparison operators, python int and float are comparable without throwing any error, they can be become equal(if no value after decimal point). 

But "1"==1 will return False as their types are str and int respectively 

Docstring if the first thing in function, module or class are stored in documentation and can be later viewed by help() function

Int(str)- can or can't give error depending on situation as type conversion can only occur when 1 type can be converted other without the need of any intermediary type. 
Eg int('  12\n ') ==12
But int('  12.5\n')== error

Float(str) - no error
Here string should can only contain numbers, a decimal point, blank spaces and escape sequences. 

Using constant'u' with strings allow python 
to support unicode

Default output of :
int() ==0
float()==0.0
str()==""

x=2
for i in range(x):
   print(x) 
   x+=1

The output will be- 2 \n 3

Var1=Var2 generates NameError if var2 is not defined

PYHTON follows pedmas - parentheses, exponential, division, multiplication, addiction, subtraction with * and / at same priority and + and - at same priority

INT can also be defined with _ in between numbers

text=hello
print(f"{text: symbol dir num} ")

Here symbol is the character with which we want to fill the empty space 
Dir is whether text be left, right or centre align
Num is the total space we wish to fill, it fill any space left after printing the text with the symbol

In a expression multiple comparison operations can be there without an error 
Eg 1<2<3 will give out True

Integers as hexadecimal and octal:
N1=0x111 here 111 is no. in hexadecimal format
N2=0o111 here 111 is no. in octal format

Scientific notation : 3.8e6 ==3.8 x 10^6

Class of None object = <class 'NoneType' >


a python package is just a directory with a lot of modules. it should have an __init__.py file in it
to import : import package.module


Walrus Operator

The Walrus Operator allows assignment of variables within an expression while returning the value of the variable

Example:

print(my_var:="Hello World!")
# 'Hello world!'

.

Comments

Popular posts from this blog

Dictionary and Sets in Python

Insertion Sort in python

Grid Printing Code for Python