Posts

control structure for for loop

# Program to find the sum of all numbers stored in a list # List of numbers numbers = [6, 5, 3] # variable to store the sum sum = 0 # iterate over the list for val in numbers: sum = sum+val # Output: The sum is 48 print("The sum is", sum)

identity operator

Image
#identity operator a= 20 b= 20 print ("line1", "a=", a, " : ", id(a), "b=", b, ":", id(b)) if (a is b): print("line 2 - a and b have same identity") else: print ("line 2 - a and b do not have same identity") if (id(a) == id(b)): print ("line 3 - a and b have same identitiy") else: print ("line 3 - a and b do not have same identity") b= 30 print ("line 4", "a=", a, ":", id(a), "b=", b, ":", id(b)) if (a is not b): print("line 5 - a and b do not have same identity") else: print("line 5 - a and b have same identity")

membership operators

Image
#membership operator a = 10 b = 20 list1 = [1, 2, 3, 4, 5] fi ( a in list1) : print ("line 1 - a is availabe in the givent list") else: print ("line 1 -  a is not available in the given list") if ( b not in list1): print ("line 2 -  b is not availabe in the givent list") else: print ("line 2 - b is available in the given list") c= b/a if (c in list 1) : print ("line 3 - b is availabe in the givent list") else: print ("line 3 -  b is not available in the given list #membership operator  a = 10  b = 20  list1 = [1, 2, 3, 4, 5] if ( a in list1) : print ("line 1 - a is availabe in the givent list")  else: print ("line 1 -  a is not availabe in the givent list") if ( b not in list1) :   print ("line 2 -  b is not availabe in the givent list") else: print ("line 2 - b is availabe in the givent list")  c= b/a if (c in list1) :   ...

logic operation

Image
syntax error example else to else:

assignment operator

Image

comparison(comparing)& arithmetic

Image
window r = cdm (to open c window system) open note++ in ' if '      (true) in ' else'   (False)

integer, multiple , input , python string, python list

#an integer assignment counter = 100 miles = 1000.0 #a floating point name = "Jhon" #string print(counter) = 100 print(miles) = 1000 print(name) = Jhon #multiple assignment counter,miles,name = 100, 1000.0, "john" print(counter, miles, name) = 100 1000.0  john #print ("My name is", name) #input names = input("Who are you?") print (names) #input names = input("Who are you?") print ("My name is", names) #python string str= "hello world" print str =  hello world print str[0] = h print #python string str = "hello world!" print (str)   =  hello world! print (str[0]) = h print (str[2:5]) = llo print (str[2:]) =llo world print (str * 2)= hello world!hello world! print (str + "TEST") = hello world! TEST print (str[0:5]) = hello print (str, "TEST") = hello world! TEST #python list list1 = ["abcd", 768, 2.23, 'john', 70.2] tinyli...