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

Module 3 Python Introduction

python introduction
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Module 3 Python Introduction

python introduction
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 76

Module-3

Python Introduction
1. Keywords
2. Identifiers
3. Variables, Constants, Literals
4. Datatypes & Type conversions
5. Operators
6. Comments
Keywords
What you will Learn ?

a = 100

int a = 100;
Keywords
Keywords are predefined, reserved words used in Python
programming.

We cannot use a keyword as a variable name, function name,


or any other identifier.
List of Keywords
None and as assert
break continue def del
except for from global
in lambda nonlocal or
raise try while yield
False True async
await class elif
else finally if
import is not
pass return with
Identifiers
Identifiers
Identifiers are the name given to variables, classes, methods, etc.
Variable Identifiers
Method/Function Identifiers
Class Identifiers
Rules
Start with a Letter or Underscore
Followed by Letters, Digits, or Underscores
Avoid Starting with a Digit
No Special Characters(!, @, $, etc.)
Case-Sensitive (e.g: age, Age, and AGE)
Avoid Using Keywords
Valid & Invalid Identifiers

name 3d_model (starts with a digit)


age @result (contains special character)
_count for (a Python keyword)
total_price my-name (contains a hyphen, not allowed)
is_student
calculate_area
student_info
MAX_VALUE
Variables
Variables
In programming, a variable is a container (storage area)
to hold data.
Variables
Rules
Start with a Letter or Underscore
Followed by Letters, Digits, or Underscores
Avoid Starting with a Digit
No Special Characters(!, @, $, etc.)
Case-Sensitive (e.g: age, Age, and AGE)
Avoid Using Keywords
Valid & Invalid Variables

name 3d_model (starts with a digit)


age @result (contains special character)
_count for (a Python keyword)
total_price my-name (contains a hyphen, not allowed)
is_student
calculate_area
student_info
MAX_VALUE
Variables vs Identifiers
Identifiers are names given to entities like variables, functions,
etc., while variables are a specific type of identifier used to store
and manipulate data in a program
Constants
Constants
A constant is a special type of variable whose value cannot be
changed.
Literals
Literals
Literals are representations of fixed values in a program.
They can be numbers, characters, or strings, etc.
Types of Literals
1. Numeric Literals
2. String Literals
3. Boolean Literals
4. None Literal
5. Bytes and Bytearray Literals
6. Raw String Literals
7. Numeric Separator
8. Collection Literals:
- List, Tuple, Set, Dictionary
Data Types
What you will Learn ?
Text Data Type
String
str represents strings of 'hello'
characters, enclosed in single, "world"
double, or triple quotes.e.g: '''hello world'''
Numeric Data Types
int
Represents integer values
(e.g., 1, -10, 100)
float
Represents floating point or decimal values
(e.g., 3.14, -2.5)
complex
complex values (e.g., 3.14j, 1-2i)
Sequence Data Types
Tuple List
ordered ordered
immutable mutable
separated by separated by
commas commas
enclosed in enclosed in
parentheses square brackets
(e.g., (1, 2, 3)). (e.g., [1, 2, 3])
Mapping Data Types
dict
Represents unordered collections of
key-value pairs, enclosed in curly
braces (e.g., {'name': 'John', 'age': 30})..
Set Data Types
set
Represents unordered collections of
unique elements, enclosed in curly
braces (e.g., {1, 2, 3})..
Boolean Data Types
bool
bool represents boolean values, which "True"
can be either True or False. Often used "False"
for logical operations and control flow.
None Data Types
None
Represents a special object that
indicates the absence of a value or a
"null" value.
Type
conversions
Type Conversion
In programming, type conversion is the process of
converting data of one type to another.
For example: converting int data to str.
Type Conversion

Implicit Type Conversion Explicit Type Conversion


Python automatically converts Users convert the data type of
one data type to another. an object to required data type.
Conversion Hierarchy
Built-in type conversion functions
int(): Converts to an integer.
float(): Converts to a floating-point number.
str(): Converts to a string.
bool(): Converts to a boolean.
list(): Converts to a list.
tuple(): Converts to a tuple.
set(): Converts to a set.
dict(): Converts to a dictionary.
Hands on Examples
Value ERROR
Introduction to ASCII Values
The "ASCII value" of a character is a number that
represents that character in the computer's memory.
ord() & chr()
In Python, you can use the ord() function to find the ASCII value
of a character.
Answer
What you have Learnt ?
1. Datatypes
2. Type Conversion
3. ASCII Values
Operators
Arithmetic operators
Assignment Operators

Agenda Comparison Operators


Logical Operators
Topics Covered Bitwise Operators
Special Operators
Arithmetic Operators
+ Addition: Adds two operands.
- Subtraction: Subtracts the right operand
from the left operand.
* Multiplication: Multiplies two operands.
/ Division: Divides the left operand by the
right operand (returns a float).
Arithmetic Operators
Arithmetic Operators
// Floor Division: Divides the left operand by
the right operand and rounds down to the
nearest integer (returns an integer).
% Modulo: Returns the remainder of the
division.
** Exponentiation: Raises the left operand to
the power of the right operand
Arithmetic Operators
Arithmetic Operators Ans
Assignment Operators
= Assignment: Assigns the value on the right
to the variable on the left.
+= Add and Assign: Adds the right operand to
the variable on the left and assigns the result
to the variable.
-= Subtract and Assign: Subtracts the right
operand from the variable on the left and
assigns the result to the variable.
Assignment Operators
Assignment Operators
*= Multiply and Assign: Multiplies the
variable on the left by the right operand and
assigns the result to the variable.
/= Divide and Assign: Divides the variable on
the left by the right operand and assigns the
result to the variable.
//= Floor Divide and Assign: Floor divides the
variable on the left by the right operand and
assigns the result to the variable.
Assignment Operators
Assignment Operators
%= Modulo and Assign: Calculates the
remainder of the division and assigns it to
the variable.
**= Exponentiate and Assign: Raises the
variable on the left to the power of the right
operand and assigns the result to the
variable.
Assignment Operators
Comparision Operators
== Equal to: Checks if two values are equal.
!= Not equal to: Checks if two values are not
equal.
> Greater than: Checks if the left operand is
greater than the right operand.
< Less than: Checks if the left operand is less
than the right operand.
Comparision Operators
Comparision Operators
>= Greater than or equal to: Checks if the left
operand is greater than or equal to the right
operand.
<= Less than or equal to: Checks if the left
operand is less than or equal to the right
operand.
Comparision Operators
Logical Operators
and Logical AND: Returns True if both
conditions are True.
or Logical OR: Returns True if at least one
condition is True.
not Logical NOT: Returns True if the
condition is False, and vice versa.
Logical Operators
Membership Operators
in Membership: Returns True if the value is
present in the sequence.
not in Negated Membership: Returns True if
the value is not present in the sequence.
Membership Operators
Identity Operators
is Identity: Returns True if both variables
point to the same object.
is not Negated Identity: Returns True if the
variables point to different objects.
Identity Operators
Bitwise Operators
Bitwise AND (&): Sets each bit to 1 if both bits
are 1.
Bitwise OR (|): Sets each bit to 1 if at least
one of the bits is 1.
Bitwise XOR (^): Sets each bit to 1 if only one
of the bits is 1.
Bitwise NOT (~): Inverts the bits, changing 1
to 0 and 0 to 1.
Bitwise Operators
Bitwise Operators
Bitwise Left Shift (<<): Shifts the bits to the
left by a specified number of positions.
Bitwise Right Shift (>>): Shifts the bits to the
right by a specified number of positions
Bitwise Operators
Python Operator Precedence
Python Operator Precedence
What you have Learnt ?
1. Arithmetic operators
2. Assignment Operators
3. Comparison Operators
4. Logical Operators
5. Bitwise Operators
6. Operator Precedence
Comments
Comments
In computer programming, comments are hints that we use to
make our code more understandable.

Comments are completely ignored by the interpreter.


Types of Comments
Single-line comments
These comments begin with a # symbol and continue until the
end of the line.
Multi-line comments
Docstrings are enclosed in triple quotes (''' or """)
and can span multiple lines.

You might also like