Core Python
Core Python
Core Python
1. Language Fundamentals
2. Operators
3. Input and Output statements
4. Flow Controls
5. String Concepts
6. List Data Structures
7. Tuple Data Structures
8. Set Data Structures
9. Dict Data Structures
10. Functions
11. Modules
12. Packages
Advanced Python
13. OOPS
14. File Handling
15. Exception Handling
16. Regular Expressions and web Scrapping
17. Multi-Threading
18. PDBC (Python Data Base Connectivity)
19. Assertions
20. Loggings
21. Decorators
22. Generators
23. Object Serialization
Extra Topics
24. Numpy
25. Pandas
26. GUI Programming (tkinter module)
27. New Features
28. Interview Questions
Introduction:
1. Python is a general-purpose high-level programming language.
2. Python was developed by “Guido Van Rossum” in 1989 while working at National Research Institute
at Netherlands. But officially Python was made available to public in 1991.
3. The official Date of Birth for Python is “Feb 20th 1991”.
4. Python is recommended as first programming language for beginners.
Java: C:
public class HelloWorld #include<stdio.h>
{ void main()
p s v main(String[] args) {
{ print("Hello world");
SOP("Hello world"); }
}
}
Python:
print("Hello World")
5. Python is highly recommended language (C, JAVA — Statically Typed programming language,
Python — Dynamically typed language)
Guido developed Python language by taking almost all programming features from different
languages.
1. Functional Programming Features from C
2. Object Oriented Programming Features from C++
3. Scripting Language Features from Perl and Shell Script
4. Modular Programming Features from Modula-3
Python Limitations:
1. Performance wise not up to the mark because it is interpreted language. If we want better
performance on python, we can use pypy flavor (jit compiler + PVM).
2. Not using for mobile Applications because don't have library support.
3. We can't use for end-to-end Enterprise applications like Banking, telecom applications.
Python Flavors:
1. CPython: It is the standard flavor of Python. It can be used to work with C language Applications
2. Jython or JPython: It is for Java Applications. It can run on JVM
3. Iron Python: It is for C#.Net platform
4. PyPy: The main advantage of PyPy is performance will be improved because JIT compiler is
available inside PVM.
5. Ruby Python: For Ruby Platforms
6. Anaconda Python: It is specially designed for handling large volume of data processing.
Python Versions:
1. Python 1.0V introduced in Jan 1994
2. Python 2.0V introduced in October 2000
3. Python 3.0V introduced in December 2008
Note: Current version is 3.10.1
IDENTIFIERS:
A Name in Python Program is called Identifier. It may be Class Name or Function Name or Module Name or
Variable Name.
Ex: a = 10
Rules to define Identifiers in Python:
1. The only allowed characters in Python are
a. alphabet symbols (either lower case or upper case)
b. digits (0 to 9)
c. underscore symbol (_).
By mistake if we are using any other symbol like $ then we will get syntax error.
Ex: ca$h =20 - SyntaxError: invalid syntax
2. Identifier should not start with digit
Ex: 123total – SyntaxError: invalid decimal literal
3. Identifiers are case sensitive. Of course, Python language is case sensitive language.
Ex: total=10
TOTAL=10
4. We cannot use reserved words or Keywords as identifiers.
Ex: def = 10
5. There is no length limit for Python identifiers. But not recommended to use too lengthy identifiers,
it reduces readability.
6. Dollar ($) Symbol is not allowed in Python.
Note:
1. If Identifier is start with Underscore (_) then it indicates it is private.
2. If Identifier is start with two Underscores (_ _) then it indicates it is strongly private.
3. If Identifier is start with two Underscores (_ _) and ends with two underscores (_ _) then it indicates
it is language specific identifier, it’s defined by python and which is also known as magic methods.
Ex: __main__
RESERVED WORDS
Python keywords are special reserved words that have specific meanings and purposes and can’t be used
for anything but those specific purposes. These keywords are always available.
As of Python 3.8 onwards, there are 35 reserved words available. It may vary from version to version.
Note:
1. All Reserved words in Python contain only alphabet symbols.
2. Except the following 3 reserved words, all contain only lower-case alphabet symbols.
a. True
b. False
c. None
To get a list of all the keywords in the version of Python you’re running, and to quickly determine how
many keywords are defined, use keyword.kwlist:
import keyword
keyword.kwlist
['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']
len(keyword.kwlist)
35
Categories:
Value Keywords: True, False, None
Operator Keywords: and, or, not, in, is
Control Flow Keywords: if, elif, else
Iteration Keywords: for, while, break, continue, else
Structure Keywords: def, class, with, as, pass, lambda
Returning Keywords: return, yield
Import Keywords: import, from, as
Exception-Handling Keywords: try, except, raise, finally, else, assert
Asynchronous Programming Keywords: async, await
Variable Handling Keywords: del, global, nonlocal
29 except Python except keyword is used to catch the Please check the try keyword
exceptions thrown in try block and process it. example.
30 finally The finally statement is used with try-except def division(x, y): try: return x / y
statements. The code in finally block is always except ZeroDivisionError as e:
executed. It’s mainly used to close resources. print(e) return -1 finally: print(‘this
will always
execute’)print(division(10, 2))
print(division(10, 0))# Output this
will always execute 5.0 division by
zero this will always execute -1
31 nonlocal The nonlocal keyword is used to access the def outer(): v = ‘outer’def inner():
variables defined outside the scope of the nonlocal v v = ‘inner’inner()
block. This is always used in the nested print(v)outer()
functions to access variables defined outside.
32 yield Python yield keyword is a replacement of def multiplyByTen(*kwargs): for i in
return keyword. This is used to return values kwargs: yield i * 10a =
one by one from the function. multiplyByTen(4, 5,) # a is generator
object, an iterator# showing the
values for i in a: print(i)# Output 40
50
33 break The break statement is used with nested “for” number = 1 while True:
and “while” loops. It stops the current loop print(number) number += 2 if
execution and passes the control to the start of number > 5: break print(number) #
the loop. never executed# Output 1 3 5
34 for Python for keyword is used to iterate over the s1 = ‘Hello’ for c in s1: print(c)#
elements of a sequence or iterable object. Output H e l l o
35 not The not keyword is used for boolean not
operation.
Data Types:
Data Type represents the type of data present inside a variable. In Python we are not required to specify
the type explicitly. Based on value provided, the type will be assigned automatically. Hence Python is
dynamically Typed Language.
Python contains the following inbuilt data types:
1. Int
2. Float
3. Complex
4. Bool
5. Str
6. Bytes
7. Bytearray
8. Range
9. List
10. Tuple
11. Set
12. Frozenset
13. Dict
14. None
int: