KEMBAR78
Python Variables, Data Types, Operators.pptx
PROGRAMMING
Presented By:
Ms. Arzoo Sorout
A.P.- CSE (Cyber Security)
GREATER NOIDA INTITUTE OF TECHNOLOGY
• Short intro about Computer
System and Programming
Languages
• History of Python
• Comparison with C Language
• Python Variables
• Python Basic Operators
• Understanding Python Blocks
• Python Data Types
• Declaring and using Numeric
Data Types: int, float, etc.
Main Points:
U N I T- 1
I N T R O D U C T I O N TO
P Y T H O N
WHAT IS
COMPUTER?
• A computer is a programmable electronic device that accepts
data as input, processes it according to stored instructions, and
produces information as output.
• It consists of hardware components like a CPU, memory, and
input/output devices, all working together to store, retrieve, and
manipulate data.
• Computers range in form and size, from large servers to personal
laptops and smartphones, and are used for a vast array of tasks,
including calculations, document creation, and internet browsing.
WHAT IS A PROGRAM
& PROGRAMMING
LANGUAGE?
• A programming language is a formal language
designed to communicate instructions to a machine,
particularly a computer.
• It serves as a bridge between human logic and machine
execution, allowing programmers to write code that
computers can understand and execute to perform
specific tasks.
• A set of instructions that you give to a computer so that
it will do a particular task is known as program.
WHAT IS A PROGRAM
& PROGRAMMING
LANGUAGE?
• A programming language is a formal language
designed to communicate instructions to a machine,
particularly a computer.
• It serves as a bridge between human logic and machine
execution, allowing programmers to write code that
computers can understand and execute to perform
specific tasks.
• A set of instructions that you give to a computer so that
it will do a particular task is known as program.
INTRODUCTION TO
PYTHON
• Python is a high-level, interpreted, general-purpose programming language. It
was created by Guido van Rossum and first released in 1991. Python is known
for its clear and readable syntax, which emphasizes code readability and
reducethe cost of program maintenance.
• Python code is executed line by line by an interpreter, rather than being
compiled into machine code before execution. This allows for rapid
prototyping and easier debugging.
• Python supports object-oriented programming (OOP) paradigms, allowing for
the creation of modular and reusable code through classes and objects.
• Python can run on various operating systems, including Windows, macOS, and
Linux.
• Variables in Python do not require explicit type declarations, as their
type is determined at runtime. This offers flexibility but shifts some
type-checking responsibility to the programmer.
• Python is not specialized for any specific domain and can be used for a
wide range of applications, including:
1. Web development (e.g., Django, Flask)
2.Data science and machine learning (e.g., NumPy, Pandas, scikit-learn,
TensorFlow)
3.Automation and scripting
4.Software development
5.Scientific computing
6.Game development
• Python comes with a rich standard library and benefits from a vast and
active community that contributes numerous third-party libraries and
frameworks, extending its capabilities significantly
HISTORY OF
PYTHON
• Python, a high-level, interpreted programming
language, originated in the late 1980s. Its
development began in December 1989 by Guido
van Rossum at the Centrum Wiskunde &
Informatica (CWI) in the Netherlands. Van
Rossum aimed to create a successor to the ABC
language, incorporating features like exception
handling and improved readability. He named it
after the British comedy troupe Monty Python.
EARLY 1990S:
INITIAL VERSIONS OF PYTHON WERE DEVELOPED, WITH PYTHON 0.9.0 RELEASED IN
1991, FEATURING CLASSES, INHERITANCE, AND EXCEPTION HANDLING.
1994:
PYTHON 1.0 WAS RELEASED, MARKING A SIGNIFICANT STEP IN THE LANGUAGE'S
MATURITY AND INCLUDING FEATURES LIKE LAMBDA, MAP, FILTER, AND REDUCE.
2000:
PYTHON 2.0 WAS RELEASED, INTRODUCING LIST COMPREHENSIONS AND A GARBAGE
COLLECTION SYSTEM. THIS VERSION ALSO SAW THE INTRODUCTION OF THE PYTHON
ENHANCEMENT PROPOSAL (PEP) PROCESS FOR MANAGING LANGUAGE CHANGES.
2008:
PYTHON 3.0 (ALSO KNOWN AS PYTHON 3000 OR PY3K) WAS RELEASED, A MAJOR AND
BACKWARD-INCOMPATIBLE REVISION THAT AIMED TO FIX FUNDAMENTAL DESIGN
FLAWS AND IMPROVE CONSISTENCY.
2010S:
PYTHON'S COMMUNITY AND ECOSYSTEM GREW RAPIDLY, LEADING TO WIDESPREAD
ADOPTION IN VARIOUS FIELDS, INCLUDING WEB DEVELOPMENT, DATA SCIENCE, AND
ARTIFICIAL INTELLIGENCE.
2018:
GUIDO VAN ROSSUM STEPPED DOWN AS THE BENEVOLENT DICTATOR FOR LIFE
(BDFL) OF PYTHON, TRANSITIONING LEADERSHIP TO THE PYTHON STEERING
COUNCIL.
2020:
PYTHON 2 REACHED ITS OFFICIAL END-OF-LIFE, ENCOURAGING USERS TO MIGRATE
TO PYTHON 3.
key
Milestones:
RULES FOR PYTHON IDENTIFIERS
(AND THUS, VARIABLE NAMES):
• START WITH A LETTER OR UNDERSCORE
• CONTAIN ALPHANUMERIC CHARACTERS
AND UNDERSCORES
• CASE-SENSITIVE
• CANNOT BE A PYTHON KEYWORD
• NO SPECIAL CHARACTERS (EXCEPT
UNDERSCORE) LIKE( !, @, #, $, %, ETC.)
• SHOULD NOT CONTAIN WHITE SPACE.
KEYWORDS:
• PREDEFINED AND RESERVED WORDS WITH SPECIAL
MEANINGS.
• USED TO DEFINE THE SYNTAX AND STRUCTURE OF
PYTHON CODE.
• CANNOT BE USED AS IDENTIFIERS, VARIABLES, OR
FUNCTION NAMES.
• WRITTEN IN LOWERCASE, EXCEPT TRUE AND FALSE.
• PYTHON 3.11 HAS 35 KEYWORDS.
• THE KEYWORD MODULE PROVIDES:
1.ISKEYWORD() → CHECKS IF A STRING IS A KEYWORD.
2.KWLIST → RETURNS THE LIST OF ALL KEYWORDS.
LIST OF PYTHON KEYWORDS:
IN PYTHON, A "BLOCK" REFERS TO A GROUP OF
STATEMENTS THAT ARE EXECUTED TOGETHER AS A
SINGLE UNIT. UNLIKE SOME OTHER PROGRAMMING
LANGUAGES THAT USE BRACES OR KEYWORDS TO
DEFINE BLOCKS, PYTHON USES INDENTATION TO
DELINEATE CODE BLOCKS.
PYTHON BLOCK
INDENTATION-BASED:
THE PRIMARY WAY TO DEFINE A BLOCK IN PYTHON IS BY CONSISTENTLY
INDENTING THE STATEMENTS WITHIN THAT BLOCK. ALL STATEMENTS
BELONGING TO THE SAME BLOCK MUST HAVE THE SAME LEVEL OF
INDENTATION.
PURPOSE:
BLOCKS ARE FUNDAMENTAL FOR CONTROLLING THE FLOW OF EXECUTION
AND ORGANIZING CODE WITHIN VARIOUS STRUCTURES, INCLUDING:
• CONDITIONAL STATEMENTS: IF, ELIF, ELSE
• LOOPS: FOR, WHILE
• FUNCTION DEFINITIONS: DEF
• CLASS DEFINITIONS: CLASS
• EXCEPTION HANDLING: TRY, EXCEPT, FINALLY
• CONTEXT MANAGERS: WITH
SCOPE:
VARIABLES DEFINED WITHIN A BLOCK TYPICALLY HAVE A SCOPE LIMITED
TO THAT BLOCK, MEANING THEY ARE NOT ACCESSIBLE OUTSIDE OF IT
UNLESS EXPLICITLY PASSED OR DECLARED IN A WIDER SCOPE.
KEY CHARACTERISTICS OF PYTHON BLOCKS:
PYTHON
OPERATORS
OPERATORS ARE USED TO PERFORM OPERATIONS ON VARIABLES
AND VALUES.
PYTHON DIVIDES THE OPERATORS IN THE FOLLOWING GROUPS:
• ARITHMETIC OPERATORS
• ASSIGNMENT OPERATORS
• COMPARISON OPERATORS
• LOGICAL OPERATORS
• IDENTITY OPERATORS
• MEMBERSHIP OPERATORS
• BITWISE OPERATORS
ARITHMETIC OPERATORS
ASSIGNMENT OPERATORS
COMPARISON OPERATORS
LOGICAL OPERATORS
BITWISE OPERATORS
IDENTITY OPERATORS
MEMBERSHIP OPERATORS
OPERATORS PRECEDENCE:
write a python program to find types of a
data.
def find_data_types():
num_int = 10
print(f"The type of {num_int} is: {type(num_int)}")
num_float = 10.5
print(f"The type of {num_float} is: {type(num_float)}")
text_str = "Hello, Python!"
print(f"The type of '{text_str}' is: {type(text_str)}")
is_true = True
print(f"The type of {is_true} is: {type(is_true)}")
my_tuple = (1, "two", 3)
print(f"The type of {my_tuple} is: {type(my_tuple)}")
my_dict = {"name": "Alice", "age": 30}
print(f"The type of {my_dict} is: {type(my_dict)}")
my_set = {1, 2, 3, 2}
print(f"The type of {my_set} is: {type(my_set)}")
no_value = None
print(f"The type of {no_value} is: {type(no_value)}")
find_data_types()
The type of 10 is: <class 'int'>
The type of 10.5 is: <class 'float'>
The type of 'Hello, Python!' is: <class 'str'>
The type of True is: <class 'bool'>
The type of [1, 2, 'three', 4.0] is: <class 'list'>
The type of (1, 'two', 3) is: <class 'tuple'>
The type of {'name': 'Alice', 'age': 30} is: <class
'dict'>
The type of {1, 2, 3} is: <class 'set'>
The type of None is: <class 'NoneType'>
output
:

Python Variables, Data Types, Operators.pptx

  • 1.
    PROGRAMMING Presented By: Ms. ArzooSorout A.P.- CSE (Cyber Security) GREATER NOIDA INTITUTE OF TECHNOLOGY
  • 2.
    • Short introabout Computer System and Programming Languages • History of Python • Comparison with C Language • Python Variables • Python Basic Operators • Understanding Python Blocks • Python Data Types • Declaring and using Numeric Data Types: int, float, etc. Main Points: U N I T- 1 I N T R O D U C T I O N TO P Y T H O N
  • 3.
    WHAT IS COMPUTER? • Acomputer is a programmable electronic device that accepts data as input, processes it according to stored instructions, and produces information as output. • It consists of hardware components like a CPU, memory, and input/output devices, all working together to store, retrieve, and manipulate data. • Computers range in form and size, from large servers to personal laptops and smartphones, and are used for a vast array of tasks, including calculations, document creation, and internet browsing.
  • 4.
    WHAT IS APROGRAM & PROGRAMMING LANGUAGE? • A programming language is a formal language designed to communicate instructions to a machine, particularly a computer. • It serves as a bridge between human logic and machine execution, allowing programmers to write code that computers can understand and execute to perform specific tasks. • A set of instructions that you give to a computer so that it will do a particular task is known as program.
  • 5.
    WHAT IS APROGRAM & PROGRAMMING LANGUAGE? • A programming language is a formal language designed to communicate instructions to a machine, particularly a computer. • It serves as a bridge between human logic and machine execution, allowing programmers to write code that computers can understand and execute to perform specific tasks. • A set of instructions that you give to a computer so that it will do a particular task is known as program.
  • 10.
    INTRODUCTION TO PYTHON • Pythonis a high-level, interpreted, general-purpose programming language. It was created by Guido van Rossum and first released in 1991. Python is known for its clear and readable syntax, which emphasizes code readability and reducethe cost of program maintenance. • Python code is executed line by line by an interpreter, rather than being compiled into machine code before execution. This allows for rapid prototyping and easier debugging. • Python supports object-oriented programming (OOP) paradigms, allowing for the creation of modular and reusable code through classes and objects. • Python can run on various operating systems, including Windows, macOS, and Linux.
  • 11.
    • Variables inPython do not require explicit type declarations, as their type is determined at runtime. This offers flexibility but shifts some type-checking responsibility to the programmer. • Python is not specialized for any specific domain and can be used for a wide range of applications, including: 1. Web development (e.g., Django, Flask) 2.Data science and machine learning (e.g., NumPy, Pandas, scikit-learn, TensorFlow) 3.Automation and scripting 4.Software development 5.Scientific computing 6.Game development • Python comes with a rich standard library and benefits from a vast and active community that contributes numerous third-party libraries and frameworks, extending its capabilities significantly
  • 12.
    HISTORY OF PYTHON • Python,a high-level, interpreted programming language, originated in the late 1980s. Its development began in December 1989 by Guido van Rossum at the Centrum Wiskunde & Informatica (CWI) in the Netherlands. Van Rossum aimed to create a successor to the ABC language, incorporating features like exception handling and improved readability. He named it after the British comedy troupe Monty Python.
  • 13.
    EARLY 1990S: INITIAL VERSIONSOF PYTHON WERE DEVELOPED, WITH PYTHON 0.9.0 RELEASED IN 1991, FEATURING CLASSES, INHERITANCE, AND EXCEPTION HANDLING. 1994: PYTHON 1.0 WAS RELEASED, MARKING A SIGNIFICANT STEP IN THE LANGUAGE'S MATURITY AND INCLUDING FEATURES LIKE LAMBDA, MAP, FILTER, AND REDUCE. 2000: PYTHON 2.0 WAS RELEASED, INTRODUCING LIST COMPREHENSIONS AND A GARBAGE COLLECTION SYSTEM. THIS VERSION ALSO SAW THE INTRODUCTION OF THE PYTHON ENHANCEMENT PROPOSAL (PEP) PROCESS FOR MANAGING LANGUAGE CHANGES. 2008: PYTHON 3.0 (ALSO KNOWN AS PYTHON 3000 OR PY3K) WAS RELEASED, A MAJOR AND BACKWARD-INCOMPATIBLE REVISION THAT AIMED TO FIX FUNDAMENTAL DESIGN FLAWS AND IMPROVE CONSISTENCY. 2010S: PYTHON'S COMMUNITY AND ECOSYSTEM GREW RAPIDLY, LEADING TO WIDESPREAD ADOPTION IN VARIOUS FIELDS, INCLUDING WEB DEVELOPMENT, DATA SCIENCE, AND ARTIFICIAL INTELLIGENCE. 2018: GUIDO VAN ROSSUM STEPPED DOWN AS THE BENEVOLENT DICTATOR FOR LIFE (BDFL) OF PYTHON, TRANSITIONING LEADERSHIP TO THE PYTHON STEERING COUNCIL. 2020: PYTHON 2 REACHED ITS OFFICIAL END-OF-LIFE, ENCOURAGING USERS TO MIGRATE TO PYTHON 3. key Milestones:
  • 17.
    RULES FOR PYTHONIDENTIFIERS (AND THUS, VARIABLE NAMES): • START WITH A LETTER OR UNDERSCORE • CONTAIN ALPHANUMERIC CHARACTERS AND UNDERSCORES • CASE-SENSITIVE • CANNOT BE A PYTHON KEYWORD • NO SPECIAL CHARACTERS (EXCEPT UNDERSCORE) LIKE( !, @, #, $, %, ETC.) • SHOULD NOT CONTAIN WHITE SPACE.
  • 18.
    KEYWORDS: • PREDEFINED ANDRESERVED WORDS WITH SPECIAL MEANINGS. • USED TO DEFINE THE SYNTAX AND STRUCTURE OF PYTHON CODE. • CANNOT BE USED AS IDENTIFIERS, VARIABLES, OR FUNCTION NAMES. • WRITTEN IN LOWERCASE, EXCEPT TRUE AND FALSE. • PYTHON 3.11 HAS 35 KEYWORDS. • THE KEYWORD MODULE PROVIDES: 1.ISKEYWORD() → CHECKS IF A STRING IS A KEYWORD. 2.KWLIST → RETURNS THE LIST OF ALL KEYWORDS.
  • 19.
    LIST OF PYTHONKEYWORDS:
  • 20.
    IN PYTHON, A"BLOCK" REFERS TO A GROUP OF STATEMENTS THAT ARE EXECUTED TOGETHER AS A SINGLE UNIT. UNLIKE SOME OTHER PROGRAMMING LANGUAGES THAT USE BRACES OR KEYWORDS TO DEFINE BLOCKS, PYTHON USES INDENTATION TO DELINEATE CODE BLOCKS. PYTHON BLOCK
  • 21.
    INDENTATION-BASED: THE PRIMARY WAYTO DEFINE A BLOCK IN PYTHON IS BY CONSISTENTLY INDENTING THE STATEMENTS WITHIN THAT BLOCK. ALL STATEMENTS BELONGING TO THE SAME BLOCK MUST HAVE THE SAME LEVEL OF INDENTATION. PURPOSE: BLOCKS ARE FUNDAMENTAL FOR CONTROLLING THE FLOW OF EXECUTION AND ORGANIZING CODE WITHIN VARIOUS STRUCTURES, INCLUDING: • CONDITIONAL STATEMENTS: IF, ELIF, ELSE • LOOPS: FOR, WHILE • FUNCTION DEFINITIONS: DEF • CLASS DEFINITIONS: CLASS • EXCEPTION HANDLING: TRY, EXCEPT, FINALLY • CONTEXT MANAGERS: WITH SCOPE: VARIABLES DEFINED WITHIN A BLOCK TYPICALLY HAVE A SCOPE LIMITED TO THAT BLOCK, MEANING THEY ARE NOT ACCESSIBLE OUTSIDE OF IT UNLESS EXPLICITLY PASSED OR DECLARED IN A WIDER SCOPE. KEY CHARACTERISTICS OF PYTHON BLOCKS:
  • 22.
    PYTHON OPERATORS OPERATORS ARE USEDTO PERFORM OPERATIONS ON VARIABLES AND VALUES. PYTHON DIVIDES THE OPERATORS IN THE FOLLOWING GROUPS: • ARITHMETIC OPERATORS • ASSIGNMENT OPERATORS • COMPARISON OPERATORS • LOGICAL OPERATORS • IDENTITY OPERATORS • MEMBERSHIP OPERATORS • BITWISE OPERATORS
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 30.
    write a pythonprogram to find types of a data. def find_data_types(): num_int = 10 print(f"The type of {num_int} is: {type(num_int)}") num_float = 10.5 print(f"The type of {num_float} is: {type(num_float)}") text_str = "Hello, Python!" print(f"The type of '{text_str}' is: {type(text_str)}") is_true = True print(f"The type of {is_true} is: {type(is_true)}") my_tuple = (1, "two", 3) print(f"The type of {my_tuple} is: {type(my_tuple)}") my_dict = {"name": "Alice", "age": 30} print(f"The type of {my_dict} is: {type(my_dict)}") my_set = {1, 2, 3, 2} print(f"The type of {my_set} is: {type(my_set)}") no_value = None print(f"The type of {no_value} is: {type(no_value)}") find_data_types()
  • 31.
    The type of10 is: <class 'int'> The type of 10.5 is: <class 'float'> The type of 'Hello, Python!' is: <class 'str'> The type of True is: <class 'bool'> The type of [1, 2, 'three', 4.0] is: <class 'list'> The type of (1, 'two', 3) is: <class 'tuple'> The type of {'name': 'Alice', 'age': 30} is: <class 'dict'> The type of {1, 2, 3} is: <class 'set'> The type of None is: <class 'NoneType'> output :