1.07k likes | 2.78k Views
This Edureka Python Programming tutorial will help you learn python and understand the various basics of Python programming with examples in detail. Below are the topics covered in this tutorial: <br><br>1. Python Installation <br>2. Python Variables <br>3. Data types in Python <br>4. Operators in Python <br>5. Conditional Statements <br>6. Loops in Python <br>7. Functions in Python <br>8. Classes and Objects
E N D
www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Agenda Scripting languages Python Overview Python Installation Python Fundamentals Python Job Trends www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Scripting Languages www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Scripting Languages A scripting language supports scripts or programs written for a special run-time environment that automate the execution of tasks They are an alternative to programs executed one-by-one by a human operator They are interpreted rather than being compiled Figure: Scripting Languages Python is the most popular Scripting Language in the industry Program 1 Program 2 Program 3 Program 1 Program 2 Program 3 Script Script www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Python Overview www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Python Overview Python is a high-level dynamic programming language Python supports multiple programming paradigms including object- oriented, imperative, functional programming and procedural styles It is easy to learn and provides dynamic typing Used by vast multitude of companies around the globe M O Z I L L A Figure: Companies using Python www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Simplicity Of Python www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Simplicity Of Python ➢ Highly readable language ➢ Clean visual layout ➢ Less syntactic exceptions ➢ Superior string manipulation ➢ Elegant and dynamic typing ➢ Interpreted nature ➢ Ideal for scripting and rapid application ➢ Fit for many platforms Figure: Python IDLE IDE www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Installation www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Installation - Python 1 Download Python 3.6.0 from www.python.org/downloads and install python-3.6.0.exe on your Windows system 2 www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Installation – PyCharm IDE Download PyCharm from jetbrains.com/pycharm/download and install it on your system www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Python Fundamentals www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Python Fundamentals The following are the five fundamentals required to master Python Object & Class Datatypes Datatypes Flow Control Functions File Handling Object & Class Numbers Strings Lists Tuples Dictionaries If Else For While Continue Definition Function Call Docstring Return Reading Writing Editing Variables Functions File Flow Control Handling Functions www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Datatypes Flow Control Functions File Handling Object & Class Numbers Strings Lists Tuples Dictionaries If Else For While Continue Definition Function Call Docstring Return Reading Writing Editing Variables Functions www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Datatypes All data values in Python are represented by objects and each object or value has a datatype The type also determines the object’s attributes and items (if any) and whether the object can be altered You do not need to declare variables before using them, or declare their type No Attributes Declaration An object’s type determines what operations the object supports, or, in other words, what operations perform on the data value Python is completely object oriented, and not "statically typed" you can Datatype Features OOP Operations www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Native Datatypes Numbers Strings Boolean Bytes & ByteArray Integers, Floats, Fractions and Complex Numbers Sequences of Unicode Characters True / False Contain Single Bytes if (number % 2) = 0: even = True else: even = False a = 5 b = 7.3 c = 2 + 3j b = ‘A\nB\nC’ s = “This is a string” Tuples Sets Dictionaries Lists Ordered immutable sequences of values Unordered bags of values Unordered bags of key-value pairs Ordered sequences of values week = {‘Mon’, ‘Tue’, ‘Wed’, ‘Thu’, ‘Fri’, ‘Sat’, ‘Sun’} a = [ 1, 2.2, “Python”] t = (2, “Tuple”, “95”) d = {‘value’:5, ‘key’:125} www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Flow Control Datatypes Functions File Handling Object & Class If Else For While Continue Numbers Strings Lists Tuples Dictionaries Definition Function Call Docstring Return Reading Writing Editing Variables Functions www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Flow Control A program’s Flow Control is the order in which the program’s code executes To mimic the real world closer then you need to transform real world situations into your program For this you need to control the execution of your program statements using Flow Controls Check Turn Start Task 1 Task 4 Task 2 Task 3 Figure: Controlled Flow In Python Types of Flow Control pass continue if for while break www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
if Statement Test False if expression The Python compound statement ’if’ lets you conditionally execute blocks of statements for True Body of if while break Statement just below if continue pass Figure: Flowchart of if Statement www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
if Statement if for If No Yes password correct while break continue pass www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
for Statement Start if The repeated execution of a statement or block of statements that is controlled by an iterable expression for statement in Python supports Expression Initialization for False Condition Testing while Exit For Loop break True Executing Loop Body continue Update Expression pass Figure: Flowchart of for Statement www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
for Statement if for friendlist[i] != NULL for while Generate HTML for friendList[i] break continue pass www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
while Statement The while statement in Python supports repeated execution of a statement or block of statements that is controlled by a conditional expression if Test False Expression for True while Body Of While Loop break Statement Below While continue Difference between while and for loop pass • For loop is used when we know the number of iterations beforehand. • While is used we know the range of values but don’t know the exact number of iterations Figure: Flowchart of while Statement www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
while Statement Load 10 more stories into Newsfeed if while (end of page) for while break continue pass www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
break Statement The break statement is allowed only inside a loop body. When break executes, the loop terminates. if for If a loop is nested inside other loops, break terminates only the innermost nested loop. Test Condition Within Loop True while break False break continue Figure: Flowchart of break Statement pass www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
break Statement if for (Time = Start Of Alarm) till (Time = End Of Alarm) for while If Incoming Call Occurs break continue break Alarm pass www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
continue Statement The continue statement is allowed only inside a loop body. if When continue executes, the current iteration of the terminates, and execution continues with the next iteration of the loop. loop body for Test Condition Within Loop True continue while False break Remaining Part Of Loop continue Normal Return Of Loop pass Figure: Flowchart of continue Statement www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
continue Statement if Start Of Incoming Call End Of Incoming Call for while If Alarm Schedule Time break continue pass Continue – Alarm To Snooze www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
pass Statement Normal Return Of Loop The pass statement, which performs no action, can be used as a placeholder when a statement is syntactically required but you have nothing specific to do. if Test Condition Within Loop True Process 1 for Process Default False while True Else If Condition Else False break Condition continue True False pass pass Figure: Flowchart of pass Statement www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Functions Datatypes Flow Control File Handling Object & Class Definition Function Call Docstring Return Numbers Strings Lists Tuples Dictionaries If Else For While Continue Reading Writing Editing Variables Functions www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Functions Functions in Python is a group of related statements that performs a specific task Functions make our program more organized and help in code reusability Figure: Understanding Python functions www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Uses of Functions Uses of Functions Functions help in code reusability Functions provide organization to the code Functions provide abstraction Functions help in extensibility Figure: Reversing a string Figure: Function to reverse a string www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
File Handling Datatypes Flow Control Functions Object & Class Numbers Strings Lists Tuples Dictionaries If Else For While Continue Definition Function Call Docstring Return Reading Writing Editing Variables Functions www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
File Handling File Handling refers to those operations that are used to read or write a file To perform file handling, we need to perform these steps: 1. Open File 2. Read / Write File 3. Close File Write File Close File Open File Read File Figure: A file operation in Python takes place in the following order www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
File Handling – Opening A File Opening A File Python has a built-in function open() to open a file This function returns a file object, also called a handle, as it is used to read or modify the file accordingly ▪ ▪ www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
File Handling – Writing To A File Writing To A File In order to write into a file we need to open it in write 'w', append 'a' or exclusive creation 'x' mode. We need to be careful with the 'w' mode as it will overwrite into the file if it already exists. All previous data are erased. Writing a string or sequence of bytes (for binary files) is done using write() method. ▪ ▪ ▪ www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
File Handling – Reading From A File Reading From A File To read the content of a file, we must open the file in reading mode. We can use the read(size) method to read in size number of data. If size parameter is not specified, it reads and returns up to the end of the file ▪ ▪ www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
File Handling – Closing A File Closing A File When we are done with operations to the file, we need to properly close it. Closing a file will free up the resources that were tied with the file and is done using the close() method. ▪ ▪ www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Object & Class Flow Control Functions File Handling Datatypes Numbers Strings Lists Tuples Dictionaries If Else For While Continue Definition Function Call Docstring Return Reading Writing Editing Variables Functions www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Object & Class ➢ Python is an object oriented programming language. ➢ Object is simply a collection of data (variables) and methods (functions) that act on those data. ➢ Class is a blueprint for the object. Figure: Houses | Objects Figure: Blueprint | Class A class is like a house’s blueprint. Objects are houses created from a blueprint. Many houses can be created from a same blueprint. www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Defining Class & Creating Object We define a class using the keyword class The first string is called docstring and has a brief description about the class. A class object can be used to create new object instances (instantiation) of that class. The procedure to create an object is similar to a function call. www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Python Job Trends www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Python Job Trends The following is the Job Trend of Python across the world Python has gradually acquired a sizable share in the industry and is the market leader from 2014 Source: www.indeed.com www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Python Success Story www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Python Success Story “Python has been an important part of Google since the beginning, and remains so as the system grows and evolves. Today dozens of Google engineers use Python, and we're looking for more people with skills in this language“ Source: Peter Norvig, Director, Google “Facebook’s Tornado is a relatively simple, non-blocking Web server framework written in Python, designed to handle thousands of simultaneous connections, making it ideal for real-time Web services” Source: www.developers.facebook.com M O Z I L L A “Mozilla is moving 2 of its largest sites (addons.mozilla.org and support.mozilla.com) from PHP to Python” “When a user decides to share out an Instagram photo to Twitter or Facebook, we push that task into Gearman, a task queue system where the whole of Instagram is written in Python” Source: www.micropipes.com Source: www.engineering.instagram.com www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Summary www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Summary Installation Scripting Languages Python Overview Success Stories Python Fundamentals Job Trends www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING
Thank You … Questions/Queries/Feedback www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING