PYTHON PROGRAMMING FUNDAMENTALS =============================== COMMENTS: ======== PROGRAM INTO TWO PARTS: 1) EXECUTABLE PART WILL PROVIDE THE OUTPUT AFTER THE EXECUTION 2) NON-EXECUTABLE PART WILL NOT PROVIDE ANY OUTPUT ARE CALLED AS "COMMENTS" OR "DOCUENTATION" FOR INCREASING THE READABILITY OF THE PROGRAM. NOT MANDATORY NOT OPTIONAL BUT SUGGESTABLE. IN ANYWHERE OF THE PROGRAM FILE. ==> COMMENTS CAN BE WRITE IN TWO WAYS: WITHIN A SINGLE LINE ==> SINGLE LINE COMMENT ==> # WITHIN MULTIPLE LINES ==> MULTI LINE COMMENT ==> TRIPLE QUOTES (''' ''' OR """ """) KEYWORDS ======== ==> ALSO CALLED AS "RESERVED WORDS" ARE PRE-DEFINED WORDS IN PYTHON WHICH CAN BE ASSISTED WITH SOME MEANING OR SOME FUNCTIONALITY. ==> THERE ARE TOTAL OF 35 KEYWORDS SPECIAL VALUES ==> True, False, None conditions ==> if, elif, else looping ==> while, for etc. # WAP IN PYTHON TO MAKE LIST WITH KEYWORDS AND PRINT THEM. """ In Python: there is a module (file) which named as "keyword". In this module(file), there is a name which named as "kwlist" The "kwlist" in keyword module, pointing all the available keywords. to list all the keywords of python, we should import the "keyword" module using import keyword. """ import keyword a = keyword.kwlist ''' a is the name (identifier), can be used to represent the list of keywords and printed using print(). ''' print(a) ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'] =============================================================== IDENTIFIER ========== ==> a name in python, we can able to define multiple entities like: variables, functions, classes, objects, methods etc. ==> while programming, to name any entity we need an identifier. Rules to define an Identifier: ============================= 1) ALLOWED CHARACTERS: ALPHABETS: UPPER CASE ==> A TO Z LOWER CASE ==> a to z DIGITS : 0 TO 9 ONLY ONE SPECIAL CHARACTER: UNDERSCORE (_) 2) IDENTIFIER NEVER START WITH A DIGIT. EX: 99abc = 100 ===> Syntax Error. 99abc = 100 print(99abc) 3) IDENTIFIER SHOULD START WITH EITHER ALPHABET OR WITH UNDERSCORE. _99abc = 100 abc = 200 print(_99abc) print(abc) 4) IF THE KEYWORD IS AN IDENTIFIER ==> SYNTAX ERROR. no keyword is an identifier. 5) NO OTHER SPECIAL CHARACTERS ARE ALLOWED TO DEFINE IDENTIFIER. (SYNTAX ERROR) 6) IDENTIFIERS ARE CASE SENSITIVE. if the same name can accessed with multiple cases ==> Name Error. CASE OF TEXT WHILE NAMING: LOWER CASE ==> abc UPPER CASE ==> ABC TITLE CASE ==> Abc def ghi CAPITALIZE CASE ==> Abc Def Ghi CAMEL CASE ==> abc Def Ghi ==> suggested 7) NO LIMIT IN LENGTH OF IDENTIFIER _99abc = 100 abc = 200 # import = 300 # ab@c = 300 a = 400 aaabbababbababababababbababababababbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = 123 print(_99abc) print(abc) # print(import) # print(ab@c) # print(ABC) print(a) print(aaabbababbababababababbababababababbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) ================================================================================== DATATYPES ========= ==> type of the data ==> all datatypes in python are: inbuilt datatypes/pre-defined datatypes for each datatype, we have one class which is pre-defined ==> that every data, can be reserved with some memory type() ===== ==> pre-defined method, used to know the type of the data or class name of the data Syntax: type(data) # Knowing of type of the data a = 100 b = 1.2233 c = True d = 'eeff' print(type(a)) print(type(b)) print(type(c)) print(type(d)) id() ==== ==> pre-defined method used to get the address of any data Syntax: id(data) a = 100 b = 0.001 c = False d = 'e' print(id(a)) print(id(b)) print(id(c)) print(id(d)) print() ====== ==> pre-defined method used to print anything on the screen Syntax: print(data/id()/type()) VARIABLES TYPE CONVERSION IO OPERATIONS