Professional Documents
Culture Documents
OUTPUT
INPUT
SUM/SUB
Syntax is
Sum= int(a) + int(b)
Print (“result is” + str(sum))
…………………………………………………………………………………………………
STRING
To know the type of the variable, type is the function used. syntax :
Print(type(a))
To print the length od the variable, len is the function used. Syntax
Print(len(a))
If statement
Syntax:
Num=int(input(“enter the number”))
If num<0 : # : is used instead of {
Print(“entered value is positive”) # the statement after if should come after a gap
which indicates that statement is under the if statement
Elif (num == 0) # python use elif instead of else if
Print(‘value is zero’)
Else
Print(“value is negative”)
While statement
i=1
while (i<=10) :
print(i)
i=i+1
else :
print (“loop \n finished”) # \n will make the rest of the sentence to be printed in
next line
For
Syntax
num=int(input("enter the number"))
for i in range(1,num+1):# 1 because num number of *should be printed till
num+1
print(" "*(num-i) + "* "*i) #num-i is used to declare space
FUNCTION
syntax
Dif hey() :
Print (“hello”)
Hey()
diff between tuple() and list[]
you can add more variables to a list but not into tuple
if u want to pass lots of arguments then there is something called arbitrary arjument
valus inside function is local variables outside is global variable
key word= variables that are initialized inside a function call
to save in dictonory value={“name”=”meril”, age=”25”}
print(value.get(“age”))
each file is called modules. To import a function to other module it is possible by
following syntax
syntax:
import file_name
print(__name__) this Is used to understand frm which file the function was called
from
from file_name import function_name in this case only the function from that
file will execute
constructors are used to work automatically without calling the function
web analysis