Input-Output (IO) Operations: ============================== a = 10 # compile time definition print(a) # 10 Variable: ========= a named memory which can store of any value the data/value of variable can be varied. variable can define in two ways: 1) compile time variable definition ==> direct value assignment program can define a variable with fixed data 2) run time variable definition during the time of the running of the program, we can assign a value from the keyboard we can change for every execution time. Input ==> use to perform input actions to take any value or any type of data during the run-time of the program to define the input operation there is an inbuilt method: input() input() ======= 1) we can use to read a value from the keyboard during the execution of the program. Syntax: identifier = input() identifier = input("text") 2) input() can always read/take the data in string format only. 3) to take data as integer/float/complex/Boolean etc., we can do the type casting/type conversion to input() ex: to take integer as an input: int(), we can perform type casting to input() Syntax: datatype(input()) # input operation a = input() b = input("Enter a value for b:") c = int(input("Enter an integer value:")) d = float(input("Enter a float value:")) e = complex(input("Enter a complex value:")) f = bool(input("Enter a boolean value:")) print(type(a)) print(type(b)) print(type(c)) print(type(d)) print(type(e)) print(type(f)) Note: ==== To read any flavor of integer data (binary/octal/hexadecimal): Syntax: int(input()) ==> we can read only the decimal value ==> base-10 value Syntax: int(input(),base-value) 1) to read a binary value: identifier = int(input(),2) 2) to read an octal value: identifier = int(input(),8) 3) to read a hexadecimal value: identifier = int(input(),16) a = int(input("Enter a binary value:"),2) b = int(input("Enter an octal value:"),8) c = int(input("Enter a hexadecimal value:"),16) d = int(input("Enter a decimal value:")) print(type(a)) print(type(b)) print(type(c)) print(type(d)) =============================================================== Output Operation ================ ==> to write/print anything on the screen, output operation is used. print() ======= an inbuilt method, we can use to print any data/value on the screen. Syntax: print(identifier) ==> to print the value print(text) ==> to print a text 1) Printing of the text: ======================== Syntax: print('text can with single quotes or with double quotes') 2) Printing of values: ====================== Syntax: print(Identifier) Note: ==== ==> Python statement may or may not be terminated with semi-colon. ==> But, when we want to define two or more statements within the same line of the program we must be separate those statements with semi-colon. 3) Printing of Values along with the text: ========================================== Ex: The value of a = 123 and the value of b = 234 123 is the value of a and 234 is the value of b a = 123 and b = 234 Syntax: i) print("text with single quote or double quote", identifier) ii) print("text1",var1,"text2",var2,"text3",var3) iii) print(value,'text1',val2,'text2',val3,'text3') iv) print('text with % % % symbol'%(val1,val2,val3)) 4) Printing of text along with values using format() ==================================================== ==> string formatting Syntax: print("text1 {} text2 {} text3 {}".format(val1,val2,val3)) # printing of text print("Hi, Good morning.");print('Hello all. Welcome to Python Class.') # Printing of values a = 'This is Python Class' b = "Welcome all to update yourself in IT career." c = 100 print(a);print(b);print(c) # Printing values along with text d = 123.234 e = True f = "String" print("The Value of c = ",c) print("The Value of d = ",d) print("The Value of e = ",e) print("The value of f = ",f) print("The Value of c = ",c,"value d = ",d,"value e = ",e,"value of f = ",f) print(c,"is the value of c",d,"is the value of d",e,"is the value of e",f,"is the value of f") print("The Value of c = %s value of d = %s value of e = %s and value of f = %s"%(c,d,e,f)) # the above one is called as "string interpolation operation" # the interpolation is fixed with %s print("The Value of c = %s value of d = %s value of e = %s and value of f = %s"%(d,e,c,f)) print("The Value of c = {} value of d = {} value of e = {} and value of f = {}".format(c,d,e,f)) print("The Value of c = {} value of d = {} value of e = {} and value of f = {}".format(d,f,c,e)) ======================================================= Assignment: ========== 1) WAP IN PYTHON TO ACCEPT AN OCTAL VALUE AS AN INPUT AND PRINT ITS DECIMAL, BINARY AND HEXADECIMAL. 0O11273 ==> DECIMAL, BINARY, HEXADECIMAL print(var-name, bin(var-name),hex(var-name))