Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
325 views

Core Python

The document contains a syllabus for learning Python that is divided into three sections: Core Python, Advanced Python, and Extra Topics. Core Python covers basic language concepts like data structures and functions. Advanced Python covers more complex topics like OOP, file handling, and regular expressions. Extra Topics includes additional libraries and skills like NumPy, Pandas, GUI programming, and interview questions. The document also provides an introduction to Python that discusses its history, uses, and key features like being free, open source, portable, and having a large standard library.

Uploaded by

Nagarjuna Reddy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
325 views

Core Python

The document contains a syllabus for learning Python that is divided into three sections: Core Python, Advanced Python, and Extra Topics. Core Python covers basic language concepts like data structures and functions. Advanced Python covers more complex topics like OOP, file handling, and regular expressions. Extra Topics includes additional libraries and skills like NumPy, Pandas, GUI programming, and interview questions. The document also provides an introduction to Python that discusses its history, uses, and key features like being free, open source, portable, and having a large standard library.

Uploaded by

Nagarjuna Reddy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Syllabus

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.

Eg1: To print Helloworld

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)

How Name Python?


The name Python was selected from the TV which was broadcasted in BBC from 1969 to 1974.

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

Note: Most of syntax in Python Derived from C and ABC languages.

Where we can use Python?


We can use everywhere. The most common important application areas are:
1. Developing Desktop Applications, web Applications, Database Applications
2. Network Programming
3. Developing games
4. Data Analysis Applications
5. Machine Learning
6. Artificial Intelligence Applications
7. IOT (Internet of Things)
Which are the Companies using Python?
1. Internally Google and YouTube use Python coding.
2. NASA and Network Stock Exchange Applications developed by Python.
3. TOP Software companies like Google, Microsoft, IBM, Yahoo using Python.
Python Features:
1. Simple and easy to learn:
Python is a simple programming language. When we read Python program, we can feel like reading
English statements.
The syntaxes are very simple and only 30+ keywords are available.
When compared with other languages, we can write programs with very a smaller number of lines.
Hence more readability and simplicity, we can reduce development and cost of the project.
Python keywords may get altered in different versions of Python. Some extra might get
added or some might be removed. You can always get the list of keywords in your current version
by typing the following in the prompt.
>>>import keyword
>>>print(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
2. Freeware and Open Source:
We can use Python software without any license, and it is freeware.
Its source code is open, so that we can we can customize based on our requirement.
Ex: Jython is customized version of Python to work with Java Applications.
3. High Level Programming language:
Python is high level programming language (human understandable language) and hence it is
programmer friendly language.
Being a programmer, we are not required to concentrate low level activities like memory
management and security etc.
4. Platform Independent:
Once we write a Python program, it can run on any platform without rewriting once again (write
once and run anywhere).
Internally "Python Virtual Machine" (PVM) is responsible to convert into machine
understandable form.
5. Portability:
Python programs are portable. i.e., we can migrate from one platform to another platform very
easily.
Python programs will provide same results on any platform.
6. Dynamically Typed:
In Python we are not required to declare type for variables. Whenever we are assigning
the value, based on value, type will be allocated automatically. Hence Python is considered as
dynamically typed language.
>>>x=10 >>>x=10.5
>>>print(type(x)) >>>print(type(x))
<class 'int'> <class 'float'>
But Java, C etc. are Statically Typed Languages because we must provide type at the
beginning only.
This dynamic typing nature Will provide more flexibility to the programmer.
7. Both Procedure Oriented and Object Oriented:
Python language supports both Procedure oriented (like C, Pascal etc.) and Object
oriented (like C++, Java) features. Hence, we can get benefits of both like security and
reusability etc.
8. Interpreted:
We are not required to compile Python programs explicitly. Internally Python interpreter Will take
care that compilation.
If compilation fails interpreter raises syntax errors. Once compilation success then
PVM (Python Virtual Machine) is responsible to execute.
9. Extensible:
We can use other language programs in Python, the main advantages of this approach are:
We can use already existing legacy non-Python code.
We can improve performance of the application
10. Embedded:
We can use Python programs in any other language programs. i.e., we can embed Python programs
anywhere.
11. Extensive Library:
Python has a rich inbuilt library.
Being a programmer, we can use this library directly and we are not responsible to
implement the functionality. Etc.

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

Useful link for python keywords: https://realpython.com/python-keywords/

Brief Introduction of the Python Keywords:

S.No Keyword Description Example


1 FALSE instance of class bool. x = False
2 class keyword to define a class. class Foo: pass
3 from clause to import class from module from collections import OrderedDict
4 or Boolean operator x = True or False
5 None instance of NoneType object x = None
6 continue continue statement, used in the nested for and numbers = range(1,11) for number
while loop. It continues with the next cycle of in numbers: if number == 7:
the nearest enclosing loop. continue
7 global global statement allows us to modify the x = 0 def add(): global x x = x + 10
variables outside the current scope. add() print(x) # 10
8 pass Python pass statement is used to do nothing. It def foo(): pass
is useful when we require some statement but
we don’t want to execute any code.
9 TRUE instance of bool class. x = True
10 def keyword used to define a function. def bar(): print(“Hello”)
11 if if statement is used to write conditional code x = 10 if x%2 == 0: print(“x is even”)
block. # prints “x is even”
12 raise The raise statement is used to throw def square(x): if type(x) is not int:
exceptions in the program. raise TypeError(“Require int
argument”) print(x * x)
13 and Boolean operator for and operation. x = True y = Falseprint(x and y) #
False
14 del The del keyword is used to delete objects such s1 = “Hello” print(s1) # Hello del s1
as variables, list, objects, etc. print(s1) # NameError: name ‘s1’ is
not defined
15 import The import statement is used to import # importing class from a module
modules and classes into our program. from collections import
OrderedDict# import module
import math
16 return The return statement is used in the function to def add(x,y): return x+y
return a value.
17 as Python as keyword is used to provide name for from collections import OrderedDict
import, except, and with statement. as od import math as mwith
open(‘data.csv’) as file: pass # do
some processing on filetry: pass
except TypeError as e: pass
18 elif The elif statement is always used with if x = 10if x > 10: print(‘x is greater
statement for “else if” operation. than 10’) elif x > 100: print(‘x is
greater than 100’) elif x == 10:
print(‘x is equal to 10’) else: print(‘x
is less than 10’)
19 in Python in keyword is used to test membership. l1 = [1, 2, 3, 4, 5]if 2 in l1: print(‘list
contains 2’)s = ‘abcd’if ‘a’ in s:
print(‘string contains a’)
20 try Python try statement is used to write x = ” try: i = int(x) except ValueError
exception handling code. as ae: print(ae)# invalid literal for
int() with base 10: ”
21 assert The assert statement allows us to insert def divide(a, b): assert b != 0 return
debugging assertions in the program. If the a/b
assertion is True, the program continues to
run. Otherwise AssertionError is thrown.
22 else The else statement is used with if-elif if False: pass else: print(‘this will
conditions. It is used to execute statements always print’)
when none of the earlier conditions are True.
23 is Python is keyword is used to test if two fruits = [‘apple’] fruits1 = [‘apple’] f
variables refer to the same object. This is same
= fruits print(f is fruits) # True
as using == operator. print(fruits1 is fruits) # False
24 while The while statement is used to run a block of i = 0 while i < 3: print(i) i+=1#
statements till the expression is True. Output # 0 # 1 # 2
25 async New keyword introduced in Python 3.5. This import asyncio import timeasync
keyword is always used in couroutine function def ping(url): print(f’Ping Started for
body. It’s used with asyncio module and await {url}’) await asyncio.sleep(1)
keywords. print(f’Ping Finished for {url}’)async
def main(): await
asyncio.gather( ping(‘askpython.co
m’), ping(‘python.org’), )if
__name__ == ‘__main__’: then =
time.time() loop =
asyncio.get_event_loop()
loop.run_until_complete(main())
now = time.time() print(f’Execution
Time = {now – then}’)# Output Ping
Started for askpython.com Ping
Started for python.org Ping Finished
for askpython.com Ping Finished for
python.org Execution Time =
1.004091739654541
26 await New keyword in Python 3.5 for asynchronous Above example demonstrates the
processing. use of async and await keywords.
27 lambda The lambda keyword is used to create lambda multiply = lambda a, b: a * b
expressions. print(multiply(8, 6)) # 48
28 with Python with statement is used to wrap the with open(‘data.csv’) as file:
execution of a block with methods defined by a file.read()
context manager. The object must implement
__enter__() and __exit__() functions.

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:

You might also like