Python Basics | Python Tutorial | Edureka
- 2. What is Python?
Features of Python
Who uses Python?
Starting off with Python Basics
❖Data Types
❖Operators
❖Flow Control
❖Functions
❖File Handling
www.edureka.co
www.edureka.co/python
- 4. What is Python?
• Created by Guido Van Rossum in 1989
• Inspired by his favorite show’s(Flying Circus)
creator ‘Monty Python’
• High Level, Interpreted language with easy syntax
and dynamic semantics
www.edureka.co/python
Open Source
OOPS
Large Standard
Library
Easy to Learn
- 6. Features of Python
Python is designed such that you think more of the code and less of the syntax
www.edureka.co/python
Simplicity
- 7. Features of Python
Being Open Source is awesome, which means that Python is free for everyone to use
www.edureka.co/python
Open Source
- 8. Features of Python
Python code can be written in one computer and executed in another without any
hassles, making code sharing much easier
www.edureka.co/python
Portability
- 9. Features of Python
Python allows code of other languages such as C, C++ to be embedded into it so that certain functions
can be performed, making Python even more powerful
www.edureka.co/python
Embeddable
and Extensible
- 10. Features of Python
The tasks of CPU and Memory Management are handled by Python itself
www.edureka.co/python
Interpreted
- 11. Features of Python
Python has a huge set of libraries such as NumPy, Matplotlib and Scikit-learn which help in solving problems
www.edureka.co/python
Huge
Libraries
- 12. Features of Python
Object Orientation helps break down complex problems of the world into code and
help provide security to it to obtain better solutions
www.edureka.co/python
Object
Orientation
- 16. Copyright © 2017, edureka and/or its affiliates. All rights reserved.
www.edureka.co
www.edureka.co/python
- 17. Starting off with Python Basics
Head over to python.org to install Python
Download Section -> Download latest version
www.edureka.co/python
- 22. Program with PyCharm
www.edureka.co/python
Program 1 :
Program 2 :
a = 10
b = 20
c = a + b
print('The addition of a and b is: %d' % c)
a = int(input('Enter number for a: '))
b = int(input('Enter number for b: '))
print('The addition of a and b is: %d' % (a + b))
- 24. Data Types in Python
www.edureka.co/python
Numeric
Lists
Tuples
Dictionary
Sets
Strings
- 25. www.edureka.co/python
• Numeric Data types
are used to store
numerical values in
the variables
• Numeric data types
are not mutable
Types Examples
Integer 1, 5, 356
Float 3.142
Complex 10 + 3j
Data Types in Python
Numeric
Lists
Tuples
Dictionary
Sets
Strings
- 26. www.edureka.co/python
• Lists are the same as arrays
• Lists can have heterogenous
data types in them
• Lists are mutable
Data Types in Python
Example:
a = [1, ‘Hindi’, 3.142, 10+6j]
Numeric
Lists
Tuples
Dictionary
Sets
Strings
- 27. www.edureka.co/python
• Tuples are the same as lists
with the exception that they
are not mutable
• This makes Tuples faster than
lists
Example:
a = (1, ‘Hindi’, 3.142, 10+6j)
Data Types in Python
Numeric
Lists
Tuples
Dictionary
Sets
Strings
- 28. www.edureka.co/python
• Dictionaries are used to hold
key, value pairs
• Dictionaries are mutable
Data Types in Python
Example:
mydict = { ‘Name’ : ‘Akash’,
‘Sign’ : ‘Libra’ }
Numeric
Lists
Tuples
Dictionary
Sets
Strings
- 29. www.edureka.co/python
• Sets are un-ordered
collection of unique
elements
• Sets are mutable
Example:
a = {1, 2, 3, 4, 4, 5}
Data Types in Python
Numeric
Lists
Tuples
Dictionary
Sets
Strings
- 30. www.edureka.co/python
• Strings are a collection of
characters
• They are written within
single (‘’) or double (“”)
quotation marks
• Strings are not mutable
Example:
string = ‘Welcome to edureka!’
Data Types in Python
Numeric
Lists
Tuples
Dictionary
Sets
Strings
- 32. Operators in Python
• Operators are constructs you use to manipulate data
• Describes actions that need to be done
• Derive information from data or manipulate them to obtain
solutions
www.edureka.co/python
01 Arithmetic Operators
02 Assignment Operators
03 Comparison Operators
04 Logical Operators
05 Bitwise Operators
06 Identity Operators
07 Membership Operators
- 33. Operators
Used to perform arithmetic operations
www.edureka.co/python
Operator Description
+ Adds 2 numbers
- Subtracts 2 numbers
* Multiplies 2 numbers
/ Divide the numbers
% Find remainder
** Raise to the power
01 Arithmetic Operators
02 Assignment Operators
03 Comparison Operators
04 Logical Operators
05 Bitwise Operators
06 Identity Operators
07 Membership Operators
- 34. Operators
Used to assign values to variables
www.edureka.co/python
Operator Description
= Assign the value
+= Add and assign
-= Subtract and assign
*= Multiply and assign
/= Divide and assign
%= Find remainder and assign
**= Find exponential and assign
01 Arithmetic Operators
02 Assignment Operators
03 Comparison Operators
04 Logical Operators
05 Bitwise Operators
06 Identity Operators
07 Membership Operators
- 35. Operators
Used to compare values
www.edureka.co/python
Operator Description
== Compare if true
!= Compare if not true
< Check if less than
> Check if greater than
<= Check if lesser or equal to
>= Check if greater or equal to
01 Arithmetic Operators
02 Assignment Operators
03 Comparison Operators
04 Logical Operators
05 Bitwise Operators
06 Identity Operators
07 Membership Operators
- 36. Operators
Used to obtain logic from the operands
www.edureka.co/python
Operator Description
and True if both are true
or True if either is true
not Gives the opposite
01 Arithmetic Operators
02 Assignment Operators
03 Comparison Operators
04 Logical Operators
05 Bitwise Operators
06 Identity Operators
07 Membership Operators
- 37. Operators
Used to manipulate the bits of the value directly.
www.edureka.co/python
Operator Description
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
~ Give 1’s Complement
<< Perform left shift
>> Perform right shift
01 Arithmetic Operators
02 Assignment Operators
03 Comparison Operators
04 Logical Operators
05 Bitwise Operators
06 Identity Operators
07 Membership Operators
- 38. Operators
Check whether values are identical or not
www.edureka.co/python
Operator Description
is If identical, then true
is not If not identical, then true
01 Arithmetic Operators
02 Assignment Operators
03 Comparison Operators
04 Logical Operators
05 Bitwise Operators
06 Identity Operators
07 Membership Operators
- 39. Operators
www.edureka.co/python
Check whether a value exists or not
Operator Description
in True if element exists
not in True if element not present
01 Arithmetic Operators
02 Assignment Operators
03 Comparison Operators
04 Logical Operators
05 Bitwise Operators
06 Identity Operators
07 Membership Operators
- 41. Flow Control
Parts of the code where the sequence must alter, flow control comes to the rescue
www.edureka.co/python
Loops
Conditional
Statements
Flow Control
If-else
while
for
- 42. Conditional Statements
• Conditional statements in Python are if-else
statements
• This is a simple if-else ladder
• if-else can be within other if-else conditions called as
nested conditions
www.edureka.co/python
- 43. Loops
Loops are used when we want to execute a certain set of statements for different inputs several times
www.edureka.co/python
Statement
Initialization
Condition
Increment
/Decrement
False
True
START
END
Statement
Condition
False
True
START
END
For Loop While Loop
- 45. Functions in Python
• Functions are blocks of code which are run whenever called
• Functions reduce redundancy and increase readability
• Python supports pass by object
Function
Built-in Function
User Defined
Function
www.edureka.co/python
- 47. File Handling
Python provides methods to handle files where
we can read and write data into it
Steps:
• Open a file
• Perform operations
• Close file
You need to make sure that you close the file to
avoid damaging data in the file
open ( filename, mode )
write( )
close( )
read( )
File Operations in Python
Opening a file
Reading a file
Writing a file
Closing a file
www.edureka.co/python
- 49. What is Python? Features of Python Who uses Python?
Starting off with Python Data Types in Python Operators in Python
Summary
www.edureka.co/python