SlideShare a Scribd company logo
Python
Python
๏‚ด Developed by Guido van Rossum
๏‚ด Derived from many other languages, including ABC, Modula-3, C, C++, Algol-68,
Smalltalk, and Unix shell and other scripting languages.
๏‚ด Python is copyrighted. Like Perl, Python source code is now available under the
GNU General Public License (GPL).
Ref: www.tutorialspoint.com Created By : Abishek
Python-Features
๏‚ด Easy-to-learn
๏‚ด Easy-to-read
๏‚ด Easy-to-maintain
๏‚ด A broad standard library
๏‚ด Interactive Mode
๏‚ด Portable
๏‚ด Extendable
๏‚ด Provide interface to all major Databases
๏‚ด Supports GUI applications
๏‚ด Scalable
Ref: www.tutorialspoint.com Created By : Abishek
Advanced Features
๏‚ด It supports functional and structured programming methods as well as OOP.
๏‚ด It can be used as a scripting language or can be compiled to byte-code for
building large applications.
๏‚ด It provides very high-level dynamic data types and supports dynamic type
checking.
๏‚ด IT supports automatic garbage collection.
๏‚ด It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.
Ref: www.tutorialspoint.com Created By : Abishek
Python Environment Variables
๏‚ด PYTHONPATH
๏‚ด PYTHONSTARTUP
๏‚ด PYTHONCASEOK
๏‚ด PYTHONHOME
Ref: www.tutorialspoint.com Created By : Abishek
Python Identifiers
๏‚ด A Python identifier is a name used to identify a variable, function, class, module or
other object.
๏‚ด Python does not allow punctuation characters such as @, $, and % within
identifiers.
๏‚ด Class names start with an uppercase letter. All other identifiers start with a
lowercase letter.
๏‚ด Starting an identifier with a single leading underscore indicates that the identifier is
private.
๏‚ด Starting an identifier with two leading underscores indicates a strongly private
identifier.
๏‚ด If the identifier also ends with two trailing underscores, the identifier is a language-
defined special name.
Ref: www.tutorialspoint.com Created By : Abishek
Reserved Words(Key words)
and exec not
assert finally or
break for pass
class from print
continue global raise
def if return
del import try
elif in while
else is with
except lambda yield
Ref: www.tutorialspoint.com Created By : Abishek
Lines and Indentation
๏‚ด Python provides no braces to indicate blocks of code for class and function
definitions or flow control.
๏‚ด Blocks of code are denoted by line indentation, which is rigidly enforced.
๏‚ด The number of spaces in the indentation is variable, but all statements within the
block must be indented the same amount.
Ref: www.tutorialspoint.com Created By : Abishek
Multi-Line Statements
๏‚ด Statements in Python typically end with a new line
๏‚ด Python allow the use of the line continuation character () to denote that the line
should continue. For Example :-
๏‚ด total = item_one + 
item_two + 
item_three
Ref: www.tutorialspoint.com Created By : Abishek
Quotation in Python
๏‚ด Python accepts single ('), double (") and triple (''' or """) quotes to denote string
literals
๏‚ด The triple quotes are used to span the string across multiple lines. For example, all
the following are legal โˆ’
๏‚ด word = 'word'
sentence = "This is a sentence."
paragraph = """This is a paragraph. It is made up of multiple lines and
sentences."""
Ref: www.tutorialspoint.com Created By : Abishek
Other Syntax in python
๏‚ด A hash sign (#) that is not inside a string literal begins a comment.
๏‚ด A line containing only whitespace, possibly with a comment, is known as a blank
line and Python totally ignores it.
๏‚ด "nn" is used to create two new lines before displaying the actual line.
๏‚ด The semicolon ( ; ) allows multiple statements on the single line given that neither
statement starts a new code block.
๏‚ด A group of individual statements, which make a single code block are
called suites in Python
Ref: www.tutorialspoint.com Created By : Abishek
Assigning Values to Variables
๏‚ด Python variables do not need explicit declaration to reserve memory space.
๏‚ด The declaration happens automatically when you assign a value to a variable. The
equal sign (=) is used to assign values to variables.
๏‚ด Python allows you to assign a single value to several variables simultaneously.
Ref: www.tutorialspoint.com Created By : Abishek
Data Types in Python
๏‚ด Python has five standard data types
๏‚ด Numbers:
๏‚ด var2 = 10
๏‚ด String
๏‚ด str = 'Hello World!'
๏‚ด List
๏‚ด list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
๏‚ด Tuple
๏‚ด tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 )
๏‚ด Dictionary
๏‚ด dict = {'name': 'john','code':6734, 'dept': 'sales'}
Ref: www.tutorialspoint.com Created By : Abishek
Data Type Conversion
Function Description
int(x [,base]) Converts x to an integer. base specifies the
base if x is a string.
long(x [,base] ) Converts x to a long integer. base specifies the
base if x is a string.
float(x) Converts x to a floating-point number.
complex(real [,imag]) Creates a complex number.
str(x) Converts object x to a string representation.
repr(x) Converts object x to an expression string.
eval(str) Evaluates a string and returns an object.
Ref: www.tutorialspoint.com Created By : Abishek
Cont.
tuple(s) Converts s to a tuple.
list(s) Converts s to a list.
set(s) Converts s to a set.
dict(d) Creates a dictionary. d must be a sequence of
(key,value) tuples.
frozenset(s) Converts s to a frozen set.
chr(x) Converts an integer to a character.
unichr(x) Converts an integer to a Unicode character.
ord(x) Converts a single character to its integer value.
hex(x) Converts an integer to a hexadecimal string.
oct(x) Converts an integer to an octal string.
Function Description
Ref: www.tutorialspoint.com Created By : Abishek
Types of Operator
๏‚ด Arithmetic Operators
๏‚ด Comparison (Relational) Operators
๏‚ด Assignment Operators
๏‚ด Logical Operators
๏‚ด Bitwise Operators
๏‚ด Membership Operators
๏‚ด Identity Operators
Ref: www.tutorialspoint.com Created By : Abishek
Decision Making
๏‚ด If statement
๏‚ด If-Else statement
๏‚ด Nested If statements
Ref: www.tutorialspoint.com Created By : Abishek
Python Loops
๏‚ด While loop
๏‚ด For loop
๏‚ด Nested loops
Ref: www.tutorialspoint.com Created By : Abishek
Loop control Statements
๏‚ด break statement
๏‚ด continue statement
๏‚ด pass statement
Ref: www.tutorialspoint.com Created By : Abishek
Python Date & Time
๏‚ด Time intervals are floating-point numbers in units of seconds. Particular instants in
time are expressed in seconds since 12:00am, January 1, 1970(epoch).
๏‚ด The function time.time() returns the current system time in ticks since 12:00am,
January 1, 1970(epoch).
๏‚ด Many of Python's time functions handle time as a tuple of 9 numbers
๏‚ด Get Current time : time.localtime(time.time())
๏‚ด Getting formatted time : time.asctime(time.localtime(time.time()))
๏‚ด Getting calendar for a month : calendar.month(year,month)
Ref: www.tutorialspoint.com Created By : Abishek
Python Functions
๏‚ด We can define the function to provide required functionality. We have to stick with some
rules and regulations to do this.
๏‚ด Function blocks begin with the keyword def followed by the function name and parentheses ( ( )
).
๏‚ด Any input parameters or arguments should be placed within these parentheses. You can also
define parameters inside these parentheses.
๏‚ด The first statement of a function can be an optional statement - the documentation string of the
function or docstring.
๏‚ด The code block within every function starts with a colon (:) and is indented.
๏‚ด The statement return [expression] exits a function, optionally passing back an expression to the
caller. A return statement with no arguments is the same as return None.
Ref: www.tutorialspoint.com Created By : Abishek
Syntax and Example for a function
๏‚ด Syntax
def functionname( parameters ):
"function_docstring"
function_suite
return [expression]
๏‚ด Example:
def printme( str ):
"This prints a passed string into this function"
print str
return
Ref: www.tutorialspoint.com Created By : Abishek
Function Arguments
๏‚ด You can call a function by using the following types of formal arguments:
๏‚ด Required arguments : Required arguments are the arguments passed to a function in
correct positional order. Here, the number of arguments in the function call should
match exactly with the function definition.
๏‚ด Keyword arguments : Keyword arguments are related to the function calls. When you
use keyword arguments in a function call, the caller identifies the arguments by the
parameter name.
๏‚ด Default arguments : A default argument is an argument that assumes a default value if
a value is not provided in the function call for that argument.
๏‚ด Variable-length arguments : You may need to process a function for more arguments
than you specified while defining the function. These arguments are called variable-
length arguments and are not named in the function definition, unlike required and
default arguments.
Ref: www.tutorialspoint.com Created By : Abishek
Anonymous Functions
๏‚ด These functions are called anonymous because they are not declared in the standard
manner by using the def keyword. You can use the lambda keyword to create small
anonymous functions.
๏‚ด Syntax: lambda [arg1 [,arg2,.....argn]]:expression
๏‚ด Lambda forms can take any number of arguments but return just one value in the form of an
expression.
๏‚ด They cannot contain commands or multiple expressions.
๏‚ด An anonymous function cannot be a direct call to print because lambda requires an expression
๏‚ด Lambda functions have their own local namespace and cannot access variables other than
those in their parameter list and those in the global namespace.
๏‚ด Although it appears that lambda's are a one-line version of a function, they are not equivalent
to inline statements in C or C++, whose purpose is by passing function stack allocation during
invocation for performance reasons.
Ref: www.tutorialspoint.com Created By : Abishek
Variables
๏‚ด Scope of a variable
๏‚ด Global variables
๏‚ด Variables that are defined outside a function body have a global scope.
๏‚ด Global variables can be accessed throughout the program body by all functions.
๏‚ด Local variables
๏‚ด Variables that are defined inside a function body have a local scope.
๏‚ด Local variables can be accessed only inside the function in which they are declared
Ref: www.tutorialspoint.com Created By : Abishek
Python Modules
๏‚ด A module is a Python object with arbitrarily named attributes that you can bind
and reference.
๏‚ด A module allows you to logically organize your Python code.
๏‚ด Grouping related code into a module makes the code easier to understand and
use.
๏‚ด A module can define functions, classes and variables. A module can also include
runnable code.
๏‚ด You can use any Python source file as a module by executing an import statement
in some other Python source file. The import has the following syntax:
๏‚ด import module1[, module2[,... moduleN]
Ref: www.tutorialspoint.com Created By : Abishek
Cont.
๏‚ด Python's from statement lets you import specific attributes from a module into the
current namespace. The from...import has the following syntax โˆ’
๏‚ด from modname import name1[, name2[, ... nameN]]
๏‚ด Using โ€˜import *โ€™ will import all names from a module into the current namespace.
๏‚ด When you import a module, the Python interpreter searches for the module in the
following sequences โˆ’
๏‚ด The current directory.
๏‚ด If the module isn't found, Python then searches each directory in the shell variable
PYTHONPATH.
๏‚ด If all else fails, Python checks the default path. On UNIX, this default path is normally
/usr/local/lib/python/.
Ref: www.tutorialspoint.com Created By : Abishek
Python I/O
๏‚ด Print statement is the simplest way to produce the output.
๏‚ด We can pass zero or more expressions separated by commas to print statement.
๏‚ด Eg: print "Python is really a great language,", "isn't it?โ€œ
๏‚ด Reading Keyboard Input
๏‚ด Python provides two built-in functions to read a line of text
๏‚ด raw_input : The raw_input([prompt]) function reads one line from standard input and returns it as
a string
๏‚ด raw_input([prompt])
๏‚ด Input : The input([prompt]) function is equivalent to raw_input, except that it assumes the input is
a valid Python expression and returns the evaluated result to you.
๏‚ด input([prompt])
Ref: www.tutorialspoint.com Created By : Abishek
Opening and Closing Files
๏‚ด The open Function
๏‚ด Open() is used to open a file
๏‚ด This function creates a file object, which would be utilized to call other support methods
associated with it.
๏‚ด Syntax: file object = open(file_name [, access_mode][, buffering])
๏‚ด file_name: The file_name argument is a string value that contains the name of the file that you
want to access.
๏‚ด access_mode: The access_mode determines the mode in which the file has to be opened, i.e.,
read, write, append, etc.
๏‚ด buffering: If the buffering value is set to 0, no buffering takes place. If the buffering value is 1,
line buffering is performed while accessing a file. If you specify the buffering value as an integer
greater than 1, then buffering action is performed with the indicated buffer size. If negative, the
buffer size is the system default(default behavior).
Ref: www.tutorialspoint.com Created By : Abishek
Cont.
๏‚ด The close() Method
๏‚ด The close() method of a file object flushes any unwritten information and closes the file
object, after which no more writing can be done.
๏‚ด Python automatically closes a file when the reference object of a file is reassigned to
another file.
๏‚ด It is a good practice to use the close() method to close a file.
๏‚ด Syntax : fileObject.close();
๏‚ด The write() Method
๏‚ด The write() method writes any string to an open file.
๏‚ด The write() method does not add a newline character ('n') to the end of the string โˆ’
๏‚ด Syntax : fileObject.write(string);
๏‚ด The read() Method
๏‚ด The read() method reads a string from an open file.
๏‚ด Syntax : fileObject.read([count]);
Ref: www.tutorialspoint.com Created By : Abishek
Python Exceptions
๏‚ด An exception is a Python object that represents an error.
๏‚ด Exception is an event, which occurs during the execution of a program that disrupts
the normal flow of the program's instructions.
๏‚ด When a Python script encounters a situation that it cannot cope with, it raises an
exception.
Ref: www.tutorialspoint.com Created By : Abishek
Handling an exception
๏‚ด Exception handling implemented in Python using try-except method.
๏‚ด You can defend your program by placing the suspicious code in a try: block.
๏‚ด After the try: block, include an except: statement, followed by a block of code which handles the problem as
elegantly as possible.
๏‚ด Syntax:
try:
You do your operations here;
......................
except ExceptionI:
If there is ExceptionI, then execute this block.
except ExceptionII:
If there is ExceptionII, then execute this block.
......................
else:
If there is no exception then execute this block.
Ref: www.tutorialspoint.com Created By : Abishek
Cont.
๏‚ด Here are few important points about the above-mentioned syntax โˆ’
๏‚ด A single try statement can have multiple except statements. This is useful when the try block
contains statements that may throw different types of exceptions.
๏‚ด You can also provide a generic except clause, which handles any exception.
๏‚ด After the except clause(s), you can include an else-clause. The code in the else-block executes if
the code in the try: block does not raise an exception.
๏‚ด The else-block is a good place for code that does not need the try: block's protection.
๏‚ด The except Clause with No Exceptions
๏‚ด You can also use the except statement with no exceptions defined as follows โˆ’
try:
You do your operations here;
......................
except:
If there is any exception, then execute this block.
......................
else:
If there is no exception then execute this block.
Ref: www.tutorialspoint.com Created By : Abishek
Cont.
๏‚ด The except Clause with Multiple Exceptions
๏‚ด You can also use the same except statement to handle multiple exceptions as follows โˆ’
try:
You do your operations here;
......................
except(Exception1[, Exception2[,...ExceptionN]]]):
If there is any exception from the given exception list,
then execute this block.
......................
else:
If there is no exception then execute this block.
Ref: www.tutorialspoint.com Created By : Abishek
Cont.
๏‚ด The try-finally Clause
๏‚ด You can use a finally: block along with a try: block.
๏‚ด The finally block is a place to put any code that must execute, whether the try-block
raised an exception or not.
๏‚ด Syntax:
try:
You do your operations here;
......................
Due to any exception, this may be skipped.
finally:
This would always be executed.
......................
Ref: www.tutorialspoint.com Created By : Abishek

More Related Content

What's hot (19)

PDF
Bcsl 031 solve assignment
Indira Gnadhi National Open University (IGNOU)
ย 
PPTX
Lexical analyzer
kiran acharya
ย 
PDF
Python revision tour i
Mr. Vikram Singh Slathia
ย 
PDF
Consuming and Creating Libraries in C++
Richard Thomson
ย 
PDF
Top C Language Interview Questions and Answer
Vineet Kumar Saini
ย 
PDF
C programming notes
Prof. Dr. K. Adisesha
ย 
PPT
C++ Interview Questions
Kaushik Raghupathi
ย 
PDF
Lesson 03 python statement, indentation and comments
Nilimesh Halder
ย 
PDF
Functional programming in C++
Alexandru Bolboaca
ย 
PPTX
Lexical analysis-using-lex
Dattatray Gandhmal
ย 
PDF
DEFUN 2008 - Real World Haskell
Bryan O'Sullivan
ย 
PPTX
Introduction to Python Part-1
Devashish Kumar
ย 
PDF
Functional Programming in C# and F#
Alfonso Garcia-Caro
ย 
PPTX
Introduction to Python Basics
Raghunath A
ย 
PPTX
Python Session - 4
AnirudhaGaikwad4
ย 
PPT
OOP in C++
ppd1961
ย 
PPT
Introduction to C++
Bharat Kalia
ย 
PPT
C, C++ Interview Questions Part - 1
ReKruiTIn.com
ย 
PDF
Python regular expressions
Krishna Nanda
ย 
Lexical analyzer
kiran acharya
ย 
Python revision tour i
Mr. Vikram Singh Slathia
ย 
Consuming and Creating Libraries in C++
Richard Thomson
ย 
Top C Language Interview Questions and Answer
Vineet Kumar Saini
ย 
C programming notes
Prof. Dr. K. Adisesha
ย 
C++ Interview Questions
Kaushik Raghupathi
ย 
Lesson 03 python statement, indentation and comments
Nilimesh Halder
ย 
Functional programming in C++
Alexandru Bolboaca
ย 
Lexical analysis-using-lex
Dattatray Gandhmal
ย 
DEFUN 2008 - Real World Haskell
Bryan O'Sullivan
ย 
Introduction to Python Part-1
Devashish Kumar
ย 
Functional Programming in C# and F#
Alfonso Garcia-Caro
ย 
Introduction to Python Basics
Raghunath A
ย 
Python Session - 4
AnirudhaGaikwad4
ย 
OOP in C++
ppd1961
ย 
Introduction to C++
Bharat Kalia
ย 
C, C++ Interview Questions Part - 1
ReKruiTIn.com
ย 
Python regular expressions
Krishna Nanda
ย 

Similar to Python Programming Basics for begginners (20)

PPTX
c & c++ logic building concepts practice.pptx
rawatsatish0327
ย 
PPTX
Functions in C++
home
ย 
PPTX
python and perl
Mara Angelica Refraccion
ย 
PDF
Python Programming Course Presentations
DreamerInfotech
ย 
PPT
presentation_intro_to_python
gunanandJha2
ย 
PPT
presentation_intro_to_python_1462930390_181219.ppt
MohitChaudhary637683
ย 
PPTX
11-unit1chapter02pythonfundamentals-180823043011.pptx
MamtaKaundal1
ย 
PDF
3-Python Python oho pytho hdiwefjhdsjhds
hardikbhagwaria83
ย 
PDF
PythonStudyMaterialSTudyMaterial.pdf
data2businessinsight
ย 
PDF
12 computer science_notes_ch01_overview_of_cpp
sharvivek
ย 
PPT
Python1
AllsoftSolutions
ย 
PPTX
Introduction to Python for Data Science and Machine Learning
ParrotAI
ย 
PPTX
6 assembly language computer organization
wewiv47743
ย 
PDF
7986-lect 7.pdf
RiazAhmad521284
ย 
PPT
An Overview Of Python With Functional Programming
Adam Getchell
ย 
DOC
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc
abdulhaq467432
ย 
PPTX
Gude for C++11 in Apache Traffic Server
Apache Traffic Server
ย 
PPTX
Introduction to R for beginners
Abishek Purushothaman
ย 
PPTX
Python
Aashish Jain
ย 
PPTX
Functions in C++
home
ย 
c & c++ logic building concepts practice.pptx
rawatsatish0327
ย 
Functions in C++
home
ย 
python and perl
Mara Angelica Refraccion
ย 
Python Programming Course Presentations
DreamerInfotech
ย 
presentation_intro_to_python
gunanandJha2
ย 
presentation_intro_to_python_1462930390_181219.ppt
MohitChaudhary637683
ย 
11-unit1chapter02pythonfundamentals-180823043011.pptx
MamtaKaundal1
ย 
3-Python Python oho pytho hdiwefjhdsjhds
hardikbhagwaria83
ย 
PythonStudyMaterialSTudyMaterial.pdf
data2businessinsight
ย 
12 computer science_notes_ch01_overview_of_cpp
sharvivek
ย 
Python1
AllsoftSolutions
ย 
Introduction to Python for Data Science and Machine Learning
ParrotAI
ย 
6 assembly language computer organization
wewiv47743
ย 
7986-lect 7.pdf
RiazAhmad521284
ย 
An Overview Of Python With Functional Programming
Adam Getchell
ย 
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc
abdulhaq467432
ย 
Gude for C++11 in Apache Traffic Server
Apache Traffic Server
ย 
Introduction to R for beginners
Abishek Purushothaman
ย 
Python
Aashish Jain
ย 
Functions in C++
home
ย 
Ad

More from Abishek Purushothaman (7)

PPTX
Aws solution architect
Abishek Purushothaman
ย 
PPTX
Machine learning
Abishek Purushothaman
ย 
DOCX
Multiple choice questions for Java io,files and inheritance
Abishek Purushothaman
ย 
DOCX
Multiple Choice Questions for Java interfaces and exception handling
Abishek Purushothaman
ย 
PPTX
Mini Project presentation for MCA
Abishek Purushothaman
ย 
PPTX
Interfaces in java
Abishek Purushothaman
ย 
PPT
Exception handling
Abishek Purushothaman
ย 
Aws solution architect
Abishek Purushothaman
ย 
Machine learning
Abishek Purushothaman
ย 
Multiple choice questions for Java io,files and inheritance
Abishek Purushothaman
ย 
Multiple Choice Questions for Java interfaces and exception handling
Abishek Purushothaman
ย 
Mini Project presentation for MCA
Abishek Purushothaman
ย 
Interfaces in java
Abishek Purushothaman
ย 
Exception handling
Abishek Purushothaman
ย 
Ad

Recently uploaded (20)

PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
ย 
PPTX
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
ย 
PPTX
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
ย 
PPTX
WYSIWYG Web Builder Crack 2025 โ€“ Free Download Full Version with License Key
HyperPc soft
ย 
PDF
Dealing with JSON in the relational world
Andres Almiray
ย 
PDF
>Wondershare Filmora Crack Free Download 2025
utfefguu
ย 
PDF
Power BI vs Tableau vs Looker - Which BI Tool is Right for You?
MagnusMinds IT Solution LLP
ย 
PDF
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
ย 
PDF
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
ย 
PDF
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
ย 
PPTX
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
ย 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
ย 
PPTX
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
ย 
PPTX
For my supp to finally picking supp that work
necas19388
ย 
PPTX
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
ย 
PDF
IDM Crack with Internet Download Manager 6.42 Build 41
utfefguu
ย 
PPTX
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
ย 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
ย 
PPTX
Mistakes to Avoid When Selecting Policy Management Software
Insurance Tech Services
ย 
PDF
IObit Uninstaller Pro 14.3.1.8 Crack for Windows Latest
utfefguu
ย 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
ย 
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
ย 
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
ย 
WYSIWYG Web Builder Crack 2025 โ€“ Free Download Full Version with License Key
HyperPc soft
ย 
Dealing with JSON in the relational world
Andres Almiray
ย 
>Wondershare Filmora Crack Free Download 2025
utfefguu
ย 
Power BI vs Tableau vs Looker - Which BI Tool is Right for You?
MagnusMinds IT Solution LLP
ย 
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
ย 
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
ย 
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
ย 
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
ย 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
ย 
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
ย 
For my supp to finally picking supp that work
necas19388
ย 
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
ย 
IDM Crack with Internet Download Manager 6.42 Build 41
utfefguu
ย 
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
ย 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
ย 
Mistakes to Avoid When Selecting Policy Management Software
Insurance Tech Services
ย 
IObit Uninstaller Pro 14.3.1.8 Crack for Windows Latest
utfefguu
ย 

Python Programming Basics for begginners

  • 2. Python ๏‚ด Developed by Guido van Rossum ๏‚ด Derived from many other languages, including ABC, Modula-3, C, C++, Algol-68, Smalltalk, and Unix shell and other scripting languages. ๏‚ด Python is copyrighted. Like Perl, Python source code is now available under the GNU General Public License (GPL). Ref: www.tutorialspoint.com Created By : Abishek
  • 3. Python-Features ๏‚ด Easy-to-learn ๏‚ด Easy-to-read ๏‚ด Easy-to-maintain ๏‚ด A broad standard library ๏‚ด Interactive Mode ๏‚ด Portable ๏‚ด Extendable ๏‚ด Provide interface to all major Databases ๏‚ด Supports GUI applications ๏‚ด Scalable Ref: www.tutorialspoint.com Created By : Abishek
  • 4. Advanced Features ๏‚ด It supports functional and structured programming methods as well as OOP. ๏‚ด It can be used as a scripting language or can be compiled to byte-code for building large applications. ๏‚ด It provides very high-level dynamic data types and supports dynamic type checking. ๏‚ด IT supports automatic garbage collection. ๏‚ด It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java. Ref: www.tutorialspoint.com Created By : Abishek
  • 5. Python Environment Variables ๏‚ด PYTHONPATH ๏‚ด PYTHONSTARTUP ๏‚ด PYTHONCASEOK ๏‚ด PYTHONHOME Ref: www.tutorialspoint.com Created By : Abishek
  • 6. Python Identifiers ๏‚ด A Python identifier is a name used to identify a variable, function, class, module or other object. ๏‚ด Python does not allow punctuation characters such as @, $, and % within identifiers. ๏‚ด Class names start with an uppercase letter. All other identifiers start with a lowercase letter. ๏‚ด Starting an identifier with a single leading underscore indicates that the identifier is private. ๏‚ด Starting an identifier with two leading underscores indicates a strongly private identifier. ๏‚ด If the identifier also ends with two trailing underscores, the identifier is a language- defined special name. Ref: www.tutorialspoint.com Created By : Abishek
  • 7. Reserved Words(Key words) and exec not assert finally or break for pass class from print continue global raise def if return del import try elif in while else is with except lambda yield Ref: www.tutorialspoint.com Created By : Abishek
  • 8. Lines and Indentation ๏‚ด Python provides no braces to indicate blocks of code for class and function definitions or flow control. ๏‚ด Blocks of code are denoted by line indentation, which is rigidly enforced. ๏‚ด The number of spaces in the indentation is variable, but all statements within the block must be indented the same amount. Ref: www.tutorialspoint.com Created By : Abishek
  • 9. Multi-Line Statements ๏‚ด Statements in Python typically end with a new line ๏‚ด Python allow the use of the line continuation character () to denote that the line should continue. For Example :- ๏‚ด total = item_one + item_two + item_three Ref: www.tutorialspoint.com Created By : Abishek
  • 10. Quotation in Python ๏‚ด Python accepts single ('), double (") and triple (''' or """) quotes to denote string literals ๏‚ด The triple quotes are used to span the string across multiple lines. For example, all the following are legal โˆ’ ๏‚ด word = 'word' sentence = "This is a sentence." paragraph = """This is a paragraph. It is made up of multiple lines and sentences.""" Ref: www.tutorialspoint.com Created By : Abishek
  • 11. Other Syntax in python ๏‚ด A hash sign (#) that is not inside a string literal begins a comment. ๏‚ด A line containing only whitespace, possibly with a comment, is known as a blank line and Python totally ignores it. ๏‚ด "nn" is used to create two new lines before displaying the actual line. ๏‚ด The semicolon ( ; ) allows multiple statements on the single line given that neither statement starts a new code block. ๏‚ด A group of individual statements, which make a single code block are called suites in Python Ref: www.tutorialspoint.com Created By : Abishek
  • 12. Assigning Values to Variables ๏‚ด Python variables do not need explicit declaration to reserve memory space. ๏‚ด The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables. ๏‚ด Python allows you to assign a single value to several variables simultaneously. Ref: www.tutorialspoint.com Created By : Abishek
  • 13. Data Types in Python ๏‚ด Python has five standard data types ๏‚ด Numbers: ๏‚ด var2 = 10 ๏‚ด String ๏‚ด str = 'Hello World!' ๏‚ด List ๏‚ด list = [ 'abcd', 786 , 2.23, 'john', 70.2 ] ๏‚ด Tuple ๏‚ด tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 ) ๏‚ด Dictionary ๏‚ด dict = {'name': 'john','code':6734, 'dept': 'sales'} Ref: www.tutorialspoint.com Created By : Abishek
  • 14. Data Type Conversion Function Description int(x [,base]) Converts x to an integer. base specifies the base if x is a string. long(x [,base] ) Converts x to a long integer. base specifies the base if x is a string. float(x) Converts x to a floating-point number. complex(real [,imag]) Creates a complex number. str(x) Converts object x to a string representation. repr(x) Converts object x to an expression string. eval(str) Evaluates a string and returns an object. Ref: www.tutorialspoint.com Created By : Abishek
  • 15. Cont. tuple(s) Converts s to a tuple. list(s) Converts s to a list. set(s) Converts s to a set. dict(d) Creates a dictionary. d must be a sequence of (key,value) tuples. frozenset(s) Converts s to a frozen set. chr(x) Converts an integer to a character. unichr(x) Converts an integer to a Unicode character. ord(x) Converts a single character to its integer value. hex(x) Converts an integer to a hexadecimal string. oct(x) Converts an integer to an octal string. Function Description Ref: www.tutorialspoint.com Created By : Abishek
  • 16. Types of Operator ๏‚ด Arithmetic Operators ๏‚ด Comparison (Relational) Operators ๏‚ด Assignment Operators ๏‚ด Logical Operators ๏‚ด Bitwise Operators ๏‚ด Membership Operators ๏‚ด Identity Operators Ref: www.tutorialspoint.com Created By : Abishek
  • 17. Decision Making ๏‚ด If statement ๏‚ด If-Else statement ๏‚ด Nested If statements Ref: www.tutorialspoint.com Created By : Abishek
  • 18. Python Loops ๏‚ด While loop ๏‚ด For loop ๏‚ด Nested loops Ref: www.tutorialspoint.com Created By : Abishek
  • 19. Loop control Statements ๏‚ด break statement ๏‚ด continue statement ๏‚ด pass statement Ref: www.tutorialspoint.com Created By : Abishek
  • 20. Python Date & Time ๏‚ด Time intervals are floating-point numbers in units of seconds. Particular instants in time are expressed in seconds since 12:00am, January 1, 1970(epoch). ๏‚ด The function time.time() returns the current system time in ticks since 12:00am, January 1, 1970(epoch). ๏‚ด Many of Python's time functions handle time as a tuple of 9 numbers ๏‚ด Get Current time : time.localtime(time.time()) ๏‚ด Getting formatted time : time.asctime(time.localtime(time.time())) ๏‚ด Getting calendar for a month : calendar.month(year,month) Ref: www.tutorialspoint.com Created By : Abishek
  • 21. Python Functions ๏‚ด We can define the function to provide required functionality. We have to stick with some rules and regulations to do this. ๏‚ด Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ). ๏‚ด Any input parameters or arguments should be placed within these parentheses. You can also define parameters inside these parentheses. ๏‚ด The first statement of a function can be an optional statement - the documentation string of the function or docstring. ๏‚ด The code block within every function starts with a colon (:) and is indented. ๏‚ด The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None. Ref: www.tutorialspoint.com Created By : Abishek
  • 22. Syntax and Example for a function ๏‚ด Syntax def functionname( parameters ): "function_docstring" function_suite return [expression] ๏‚ด Example: def printme( str ): "This prints a passed string into this function" print str return Ref: www.tutorialspoint.com Created By : Abishek
  • 23. Function Arguments ๏‚ด You can call a function by using the following types of formal arguments: ๏‚ด Required arguments : Required arguments are the arguments passed to a function in correct positional order. Here, the number of arguments in the function call should match exactly with the function definition. ๏‚ด Keyword arguments : Keyword arguments are related to the function calls. When you use keyword arguments in a function call, the caller identifies the arguments by the parameter name. ๏‚ด Default arguments : A default argument is an argument that assumes a default value if a value is not provided in the function call for that argument. ๏‚ด Variable-length arguments : You may need to process a function for more arguments than you specified while defining the function. These arguments are called variable- length arguments and are not named in the function definition, unlike required and default arguments. Ref: www.tutorialspoint.com Created By : Abishek
  • 24. Anonymous Functions ๏‚ด These functions are called anonymous because they are not declared in the standard manner by using the def keyword. You can use the lambda keyword to create small anonymous functions. ๏‚ด Syntax: lambda [arg1 [,arg2,.....argn]]:expression ๏‚ด Lambda forms can take any number of arguments but return just one value in the form of an expression. ๏‚ด They cannot contain commands or multiple expressions. ๏‚ด An anonymous function cannot be a direct call to print because lambda requires an expression ๏‚ด Lambda functions have their own local namespace and cannot access variables other than those in their parameter list and those in the global namespace. ๏‚ด Although it appears that lambda's are a one-line version of a function, they are not equivalent to inline statements in C or C++, whose purpose is by passing function stack allocation during invocation for performance reasons. Ref: www.tutorialspoint.com Created By : Abishek
  • 25. Variables ๏‚ด Scope of a variable ๏‚ด Global variables ๏‚ด Variables that are defined outside a function body have a global scope. ๏‚ด Global variables can be accessed throughout the program body by all functions. ๏‚ด Local variables ๏‚ด Variables that are defined inside a function body have a local scope. ๏‚ด Local variables can be accessed only inside the function in which they are declared Ref: www.tutorialspoint.com Created By : Abishek
  • 26. Python Modules ๏‚ด A module is a Python object with arbitrarily named attributes that you can bind and reference. ๏‚ด A module allows you to logically organize your Python code. ๏‚ด Grouping related code into a module makes the code easier to understand and use. ๏‚ด A module can define functions, classes and variables. A module can also include runnable code. ๏‚ด You can use any Python source file as a module by executing an import statement in some other Python source file. The import has the following syntax: ๏‚ด import module1[, module2[,... moduleN] Ref: www.tutorialspoint.com Created By : Abishek
  • 27. Cont. ๏‚ด Python's from statement lets you import specific attributes from a module into the current namespace. The from...import has the following syntax โˆ’ ๏‚ด from modname import name1[, name2[, ... nameN]] ๏‚ด Using โ€˜import *โ€™ will import all names from a module into the current namespace. ๏‚ด When you import a module, the Python interpreter searches for the module in the following sequences โˆ’ ๏‚ด The current directory. ๏‚ด If the module isn't found, Python then searches each directory in the shell variable PYTHONPATH. ๏‚ด If all else fails, Python checks the default path. On UNIX, this default path is normally /usr/local/lib/python/. Ref: www.tutorialspoint.com Created By : Abishek
  • 28. Python I/O ๏‚ด Print statement is the simplest way to produce the output. ๏‚ด We can pass zero or more expressions separated by commas to print statement. ๏‚ด Eg: print "Python is really a great language,", "isn't it?โ€œ ๏‚ด Reading Keyboard Input ๏‚ด Python provides two built-in functions to read a line of text ๏‚ด raw_input : The raw_input([prompt]) function reads one line from standard input and returns it as a string ๏‚ด raw_input([prompt]) ๏‚ด Input : The input([prompt]) function is equivalent to raw_input, except that it assumes the input is a valid Python expression and returns the evaluated result to you. ๏‚ด input([prompt]) Ref: www.tutorialspoint.com Created By : Abishek
  • 29. Opening and Closing Files ๏‚ด The open Function ๏‚ด Open() is used to open a file ๏‚ด This function creates a file object, which would be utilized to call other support methods associated with it. ๏‚ด Syntax: file object = open(file_name [, access_mode][, buffering]) ๏‚ด file_name: The file_name argument is a string value that contains the name of the file that you want to access. ๏‚ด access_mode: The access_mode determines the mode in which the file has to be opened, i.e., read, write, append, etc. ๏‚ด buffering: If the buffering value is set to 0, no buffering takes place. If the buffering value is 1, line buffering is performed while accessing a file. If you specify the buffering value as an integer greater than 1, then buffering action is performed with the indicated buffer size. If negative, the buffer size is the system default(default behavior). Ref: www.tutorialspoint.com Created By : Abishek
  • 30. Cont. ๏‚ด The close() Method ๏‚ด The close() method of a file object flushes any unwritten information and closes the file object, after which no more writing can be done. ๏‚ด Python automatically closes a file when the reference object of a file is reassigned to another file. ๏‚ด It is a good practice to use the close() method to close a file. ๏‚ด Syntax : fileObject.close(); ๏‚ด The write() Method ๏‚ด The write() method writes any string to an open file. ๏‚ด The write() method does not add a newline character ('n') to the end of the string โˆ’ ๏‚ด Syntax : fileObject.write(string); ๏‚ด The read() Method ๏‚ด The read() method reads a string from an open file. ๏‚ด Syntax : fileObject.read([count]); Ref: www.tutorialspoint.com Created By : Abishek
  • 31. Python Exceptions ๏‚ด An exception is a Python object that represents an error. ๏‚ด Exception is an event, which occurs during the execution of a program that disrupts the normal flow of the program's instructions. ๏‚ด When a Python script encounters a situation that it cannot cope with, it raises an exception. Ref: www.tutorialspoint.com Created By : Abishek
  • 32. Handling an exception ๏‚ด Exception handling implemented in Python using try-except method. ๏‚ด You can defend your program by placing the suspicious code in a try: block. ๏‚ด After the try: block, include an except: statement, followed by a block of code which handles the problem as elegantly as possible. ๏‚ด Syntax: try: You do your operations here; ...................... except ExceptionI: If there is ExceptionI, then execute this block. except ExceptionII: If there is ExceptionII, then execute this block. ...................... else: If there is no exception then execute this block. Ref: www.tutorialspoint.com Created By : Abishek
  • 33. Cont. ๏‚ด Here are few important points about the above-mentioned syntax โˆ’ ๏‚ด A single try statement can have multiple except statements. This is useful when the try block contains statements that may throw different types of exceptions. ๏‚ด You can also provide a generic except clause, which handles any exception. ๏‚ด After the except clause(s), you can include an else-clause. The code in the else-block executes if the code in the try: block does not raise an exception. ๏‚ด The else-block is a good place for code that does not need the try: block's protection. ๏‚ด The except Clause with No Exceptions ๏‚ด You can also use the except statement with no exceptions defined as follows โˆ’ try: You do your operations here; ...................... except: If there is any exception, then execute this block. ...................... else: If there is no exception then execute this block. Ref: www.tutorialspoint.com Created By : Abishek
  • 34. Cont. ๏‚ด The except Clause with Multiple Exceptions ๏‚ด You can also use the same except statement to handle multiple exceptions as follows โˆ’ try: You do your operations here; ...................... except(Exception1[, Exception2[,...ExceptionN]]]): If there is any exception from the given exception list, then execute this block. ...................... else: If there is no exception then execute this block. Ref: www.tutorialspoint.com Created By : Abishek
  • 35. Cont. ๏‚ด The try-finally Clause ๏‚ด You can use a finally: block along with a try: block. ๏‚ด The finally block is a place to put any code that must execute, whether the try-block raised an exception or not. ๏‚ด Syntax: try: You do your operations here; ...................... Due to any exception, this may be skipped. finally: This would always be executed. ...................... Ref: www.tutorialspoint.com Created By : Abishek