Introduction - Python
- Dynamically Typed, Supports OOPS, High-Level Programming language
- Interpreted, Platform Independent
- REPL (Read Evaluate Print Loop)
- Modules
- Comments
#
=> Comment a line
""" value """
=> Multi-Line comment
''' value '''
=> Multi-Line comment
- Outputs
print(objName)
=> Object will be converted to string before printing
print(varName)
=> Print a variable
print(N * "value")
=> Print string "value" N times
print(varName1, varName2, "value")
=> Print more than one value separated by comma
print(objName, sep="")
=> Default separator is space
print(objName, end="")
=> Default line end is "\n"
print(objName, file="filePath")
=> Object with write method, Default is sys.stdout
print(objName, flush="")
- Inputs
varName = input()
=> Returns input as string
varName = int(input())
=> Typecasting input to integer
varName = input("Enter: ")
- Escape Characters
\n
=> New line
\"
=> Double-Quote
\t
=> Tab
*
=> Means all
- chr()` => Takes integer and return character of that ASCII value
ord()
=> Takes character and returns ASCII values
id()
=> Gives address of the object
format(variableName, '0.2f')
=> Round off value up to 2 decimal places, Used with print syntax
- PEP 8 (Python Enhancement Proposal)
- Document that provides guidelines and best practices on how to write Python code
import this
=> The Zen of Python