Basic Of Python
Learn Python With Sagar Jaybhay
Install python from this link
Installation Path on My machine is installation path : C:\Users\sagar\AppData\Local\Programs\Python\Python37 – which might different on your machine
Reference Link: – https://docs.python.org/3/reference/datamodel.html
Objects are Python’s abstraction for data. All data in a Python program is represented by objects or by relations between objects.
Explicit newline conversion: you can break statement overmultiple lines using \ (backslash) character.
Multi-line comment can be given by 3 single and double quotes like ‘’’ — ‘’’ or “”” —“”” is also called doc string and is also used for generation of documentation. The documentation string is also used for generating documentation automatically documentation string can be accessed at run-time using
obj.__doc__ attribute. Also, you can print this comment while assigning to a variable.
c=''' comment Raju ''' """ comment """ print(c)
Single line comment or block comment using # sign is used for single or code comment.
Identifiers in Python:
Python is case sensitive cat, CAT is different. Identifiersmust follow some rules.
- Must start with _ or letter a-zA-Z
- It can be followed by any number of underscores(_), letters or digits(0-9). When you start the name with number compiler gives an error.
- Identifier names are not reserved words.
- _my_var (single underscore) = this conventionindicates that its for internal use or private objects.
When you import something from that module which contains this variableis not imported from module import * because python interpreter thought it isprivate but you can access. It is a hint to the programmer that it is forinternal use.
- __my_var(double underscore) = it is used to mangle class attributes- useful in inheritance chains what it is meaning of name mangling? In this interpreter changes the name in a way that it makes it harder to create collisions when class is extended.
- __my_var__(double underscore start & end) = It is used for system-defined names that have special meaning to the interpreter. Do not go to create a variable using this convention.
- Packages: all in small letters and short name is preferable and try to not use underscore.
- Ex customrpts= custom reports.
- Modules: It can have underscore and name is short and all in a small case. Ex. db_connect
- Classes: Initials in the capital like BeingHuman. Is called CapWords. Ex HumanResource
- Functions: lowercase and word should separate with underscores. Ex. select_employee
- Variables: is in lowercase and word can be separated by an underscore.
- Ex. full_name
- Constants: all in upper case with word separated by an underscore.
- Ex. LNAME
All this is to maintaining the uniformness and the second developer who read or work on your code needs to easily understand for that purpose should follow specification but it’s not compulsion.