SlideShare une entreprise Scribd logo
1  sur  60
Python
https://www.programiz.com/python-programming/keywords-
identifier
Python
• Python is a cross-platform programming language, which means
that it can run on multiple platforms like Windows, macOS, Linux,
and has even been ported to the Java and .NET virtual machines.
It is free and open-source.
• Even though most of today's Linux and Mac have Python pre-
installed in it, the version might be out-of-date. So, it is always a
good idea to install the most current version.
The Easiest Way to Run Python
• The Thonny IDE comes with the latest version of Python bundled in it. So
you don't have to install Python separately.
• Follow the following steps to run Python on your computer.
1. Download Thonny IDE.
2. Run the installer to install Thonny on your computer.
• Go to: File > New. Then save the file with .py extension. For example,
hello.py, example.py, etc.
• You can give any name to the file. However, the file name should end
with .py
• Write Python code in the file and save it
Thonny Python IDE
Features
• Easy to get started. Thonny comes with Python 3.10
built in, so just one simple installer is needed and
you're ready to learn programming. (You can also use a
separate Python installation, if necessary.) The initial
user interface is stripped of all features that may
distract beginners.
continue
• Simple debugger. Just press Ctrl+F5 instead
of F5 and you can run your programs step-by-
step, no breakpoints needed. Press F6 for a
big step and F7 for a small step. Steps follow
program structure, not just code lines.
• Step through expression evaluation. If you
use small steps, then you can even see how
Python evaluates your expressions. You can
think of this light-blue box as a piece of paper
where Python replaces subexpressions with
their values, piece-by-piece.
continue
• Highlights syntax errors. Unclosed quotes and
parentheses are the most common beginners' syntax
errors. Thonny's editor makes these easy to spot.
• Code completion. Students can explore APIs with the
help of code completion.
Python Keywords and Identifiers
• Keywords are predefined, reserved words used in Python
programming that have special meanings to the compiler.
• We cannot use a keyword as a variable name, function name, or
any other identifier. They are used to define the syntax and
structure of the Python language.
• All the keywords except True, False and None are in lowercase and
they must be written as they are. The list of all the keywords is
given below.
Python Keywords List
Rules for Naming an Identifier
• Identifiers cannot be a keyword.
• Identifiers are case-sensitive.
• It can have a sequence of letters and digits. However, it must
begin with a letter or _. The first letter of an identifier cannot be
a digit.
• It's a convention to start an identifier with a letter rather
• Whitespaces are not allowed.
• We cannot use special symbols like !, @, #, $, and so on.
Things to Remember
• Python is a case-sensitive language. This means, Variable and
variable are not the same.
• Multiple words can be separated using an underscore, like
this_is_a_long_variable.
Python Comments
Python Comments
• In computer programming, comments are hints that we use to
make our code more understandable.
• Comments are completely ignored by the interpreter. They are
meant for fellow programmers. For example,
Types of Comments in Python
• In Python, there are two types of comments:
• single-line comment
• multi-line comment
• Multi-line Comment in Python
• Python doesn't offer a separate way to write multiline comments.
• We can use # at the beginning of each line of comment on
multiple lines
Python Variables, Constants and
Literals
Python Variables
• In programming, a variable is a container (storage area) to hold
data. For example,
Changing the Value of a Variable in Python
Assigning multiple values to multiple variables
Python Constants
Python Literals
• Literals are representations of fixed values in a program. They can
be numbers, characters, or strings, etc. For example, 'Hello,
World!', 12, 23.0, 'C', etc.
Python Data Types
• In computer programming, data types specify the type of data
that can be stored inside a variable. For example,
Python List Data Type
• List is an ordered collection of similar or different types of items
separated by commas and enclosed within brackets [ ]. For
example,
• Here, we have created a list named languages with 3 string values
inside it.
Access List Items
• To access items from a list, we use the index number (0, 1, 2 ...).
For example,
Python Tuple Data Type
• Tuple is an ordered sequence of items same as a list. The only
difference is that tuples are immutable. Tuples once created
cannot be modified.
• In Python, we use the parentheses () to store items of a tuple. For
example,
Access Tuple Items
• Similar to lists, we use the index number to access tuple items in
Python . For example.
Python String Data Type
Python Set Data Type
• Set is an unordered collection of unique items. Set is defined by
values separated by commas inside braces { }. For example,
Python Type Conversion
• In programming, type conversion is the process of converting data
of one type to another. For example: converting integer data to
string.
• There are two types of type conversion in Python.
• Implicit Conversion - automatic type conversion
• Explicit Conversion - manual type conversion
Python Implicit Type Conversion
• Python automatically converts one data type to another. This is
known as implicit type conversion.
• Example 1: Converting integer to float
Explicit Type Conversion
• In Explicit Type Conversion, users convert the data type of an
object to required data type.
• We use the built-in functions like int(), float(), str(), etc to
perform explicit type conversion.
• This type of conversion is also called typecasting because the user
casts (changes) the data type of the objects.
Example 2: Addition of string and integer Using Explicit
Conversion
Key Points to Remember
• Type Conversion is the conversion of an object from one data type
to another data type.
• Implicit Type Conversion is automatically performed by the Python
interpreter.
• Python avoids the loss of data in Implicit Type Conversion.
• Explicit Type Conversion is also called Type Casting, the data types
of objects are converted using predefined functions by the user.
• In Type Casting, loss of data may occur as we enforce the object
to a specific data type.
Python Basic Input and Output
• Python Output
• In Python, we can simply use the print() function to print output.
For example,
Syntax of print()
• object - value(s) to be printed
• sep (optional) - allows us to separate multiple objects inside print().
• end (optional) - allows us to add add specific values like new line "n", tab
"t"
• file (optional) - where the values are printed. It's default value is
sys.stdout (screen)
• flush (optional) - boolean specifying if the output is flushed or buffered.
Default: False
Example 2: Python print() with end Parameter
Example 3: Python print() with sep parameter
Python input & output
• While programming, we might want to take the input from the
user. In python, we can use the input() function.
Example: Print Python Variables and Literals
Example: Print Concatenated Strings
Python Input
• While programming, we might want to take the input from the
user. In Python, we can use the input() function.
• Syntax of input()
Example: Python User Input
Python Operators
Types of Python Operators
1. Arithmetic operators
2. Assignment Operators
3. Comparison Operators
4. Logical Operators
5. Bitwise Operators
6. Special Operators
1. Python Arithmetic Operators
Example 1: Arithmetic Operators in Python
2. Python Assignment Operators
• Assignment operators are used to assign values to variables. For
example,
Example 2: Assignment Operators
3. Python Comparison Operators
Example 3: Comparison Operators
4. Python Logical Operators
Python Namespace And Scope
What is Name in Python?
• Name (also called identifier) is simply a name given to objects.
Everything in Python is an object. Name is a way to access the
underlying object.
• For example, when we do the assignment a = 2, 2 is an object
stored in memory and a is the name we associate it with. We can
get the address (in RAM) of some object through the built-in
function id(). Let's look at how to use it.
Name in Python?
What is a Namespace in Python?
• To simply put it, a namespace is a collection of names.
• In Python, you can imagine a namespace as a mapping of every
name you have defined to corresponding objects.
• Different namespaces can co-exist at a given time but are
completely isolated.
• A namespace containing all the built-in names is created when we
start the Python interpreter and exists as long as the interpreter
runs.
• This is the reason that built-in functions like id(), print() etc. are
always available to us from any part of the program. Each module
creates its own global namespace.
Python Variable Scope
• A scope is the portion of a program from where a namespace can
be accessed directly without any prefix.
• At any given moment, there are at least three nested scopes.
1. Scope of the current function which has local names
2. Scope of the module which has global names
3. Outermost scope which has built-in names
Python Variable Scope
• When a reference is made inside a function, the name is searched
in the local namespace, then in the global namespace and finally
in the built-in namespace.
• If there is a function inside another function, a new scope is
nested inside the local scope.
Example of Scope and Namespace in Python
• Here, the variable a is in the global namespace. Variable b is in
the local namespace of outer_function() and c is in the nested
local namespace of inner_function().
• When we are in inner_function(), c is local to us, b is nonlocal and
a is global. We can read as well as assign new values to c but can
only read b and a from inner_function().
Python 01.pptx

Contenu connexe

Similaire à Python 01.pptx

Py-Slides- easuajsjsjejejjwlqpqpqpp1.pdf
Py-Slides- easuajsjsjejejjwlqpqpqpp1.pdfPy-Slides- easuajsjsjejejjwlqpqpqpp1.pdf
Py-Slides- easuajsjsjejejjwlqpqpqpp1.pdfshetoooelshitany74
 
Python Programming.pdf
Python Programming.pdfPython Programming.pdf
Python Programming.pdfssuser9a6ca1
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdfsamiwaris2
 
prakash ppt (2).pdf
prakash ppt (2).pdfprakash ppt (2).pdf
prakash ppt (2).pdfShivamKS4
 
Python Data types like mutable and immutable
Python Data types like mutable and immutablePython Data types like mutable and immutable
Python Data types like mutable and immutableramireddyobulakondar
 
Python presentation of Government Engineering College Aurangabad, Bihar
Python presentation of Government Engineering College Aurangabad, BiharPython presentation of Government Engineering College Aurangabad, Bihar
Python presentation of Government Engineering College Aurangabad, BiharUttamKumar617567
 
4_Introduction to Python Programming.pptx
4_Introduction to Python Programming.pptx4_Introduction to Python Programming.pptx
4_Introduction to Python Programming.pptxGnanesh12
 
Full Python in 20 slides
Full Python in 20 slidesFull Python in 20 slides
Full Python in 20 slidesrfojdar
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxNimrahafzal1
 
Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Chariza Pladin
 
Python-Certification-Training-Day-1-2.pptx
Python-Certification-Training-Day-1-2.pptxPython-Certification-Training-Day-1-2.pptx
Python-Certification-Training-Day-1-2.pptxmuzammildev46gmailco
 

Similaire à Python 01.pptx (20)

Py-Slides- easuajsjsjejejjwlqpqpqpp1.pdf
Py-Slides- easuajsjsjejejjwlqpqpqpp1.pdfPy-Slides- easuajsjsjejejjwlqpqpqpp1.pdf
Py-Slides- easuajsjsjejejjwlqpqpqpp1.pdf
 
intro to python.pptx
intro to python.pptxintro to python.pptx
intro to python.pptx
 
Python Programming.pdf
Python Programming.pdfPython Programming.pdf
Python Programming.pdf
 
Python Demo.pptx
Python Demo.pptxPython Demo.pptx
Python Demo.pptx
 
Python Demo.pptx
Python Demo.pptxPython Demo.pptx
Python Demo.pptx
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
prakash ppt (2).pdf
prakash ppt (2).pdfprakash ppt (2).pdf
prakash ppt (2).pdf
 
Python Data types like mutable and immutable
Python Data types like mutable and immutablePython Data types like mutable and immutable
Python Data types like mutable and immutable
 
Python presentation of Government Engineering College Aurangabad, Bihar
Python presentation of Government Engineering College Aurangabad, BiharPython presentation of Government Engineering College Aurangabad, Bihar
Python presentation of Government Engineering College Aurangabad, Bihar
 
4_Introduction to Python Programming.pptx
4_Introduction to Python Programming.pptx4_Introduction to Python Programming.pptx
4_Introduction to Python Programming.pptx
 
Full Python in 20 slides
Full Python in 20 slidesFull Python in 20 slides
Full Python in 20 slides
 
Class_X_PYTHON_J.pdf
Class_X_PYTHON_J.pdfClass_X_PYTHON_J.pdf
Class_X_PYTHON_J.pdf
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
 
python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
 
python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
 
Python-Basics.pptx
Python-Basics.pptxPython-Basics.pptx
Python-Basics.pptx
 
Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3
 
Python-Certification-Training-Day-1-2.pptx
Python-Certification-Training-Day-1-2.pptxPython-Certification-Training-Day-1-2.pptx
Python-Certification-Training-Day-1-2.pptx
 
Unit -1 CAP.pptx
Unit -1 CAP.pptxUnit -1 CAP.pptx
Unit -1 CAP.pptx
 

Dernier

Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 

Dernier (20)

Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 

Python 01.pptx

  • 2. Python • Python is a cross-platform programming language, which means that it can run on multiple platforms like Windows, macOS, Linux, and has even been ported to the Java and .NET virtual machines. It is free and open-source. • Even though most of today's Linux and Mac have Python pre- installed in it, the version might be out-of-date. So, it is always a good idea to install the most current version.
  • 3. The Easiest Way to Run Python • The Thonny IDE comes with the latest version of Python bundled in it. So you don't have to install Python separately. • Follow the following steps to run Python on your computer. 1. Download Thonny IDE. 2. Run the installer to install Thonny on your computer. • Go to: File > New. Then save the file with .py extension. For example, hello.py, example.py, etc. • You can give any name to the file. However, the file name should end with .py • Write Python code in the file and save it
  • 4.
  • 6. Features • Easy to get started. Thonny comes with Python 3.10 built in, so just one simple installer is needed and you're ready to learn programming. (You can also use a separate Python installation, if necessary.) The initial user interface is stripped of all features that may distract beginners.
  • 7. continue • Simple debugger. Just press Ctrl+F5 instead of F5 and you can run your programs step-by- step, no breakpoints needed. Press F6 for a big step and F7 for a small step. Steps follow program structure, not just code lines. • Step through expression evaluation. If you use small steps, then you can even see how Python evaluates your expressions. You can think of this light-blue box as a piece of paper where Python replaces subexpressions with their values, piece-by-piece.
  • 8. continue • Highlights syntax errors. Unclosed quotes and parentheses are the most common beginners' syntax errors. Thonny's editor makes these easy to spot. • Code completion. Students can explore APIs with the help of code completion.
  • 9. Python Keywords and Identifiers • Keywords are predefined, reserved words used in Python programming that have special meanings to the compiler. • We cannot use a keyword as a variable name, function name, or any other identifier. They are used to define the syntax and structure of the Python language. • All the keywords except True, False and None are in lowercase and they must be written as they are. The list of all the keywords is given below.
  • 11. Rules for Naming an Identifier • Identifiers cannot be a keyword. • Identifiers are case-sensitive. • It can have a sequence of letters and digits. However, it must begin with a letter or _. The first letter of an identifier cannot be a digit. • It's a convention to start an identifier with a letter rather • Whitespaces are not allowed. • We cannot use special symbols like !, @, #, $, and so on.
  • 12. Things to Remember • Python is a case-sensitive language. This means, Variable and variable are not the same. • Multiple words can be separated using an underscore, like this_is_a_long_variable.
  • 14. Python Comments • In computer programming, comments are hints that we use to make our code more understandable. • Comments are completely ignored by the interpreter. They are meant for fellow programmers. For example,
  • 15. Types of Comments in Python • In Python, there are two types of comments: • single-line comment • multi-line comment • Multi-line Comment in Python • Python doesn't offer a separate way to write multiline comments. • We can use # at the beginning of each line of comment on multiple lines
  • 17. Python Variables • In programming, a variable is a container (storage area) to hold data. For example,
  • 18. Changing the Value of a Variable in Python
  • 19. Assigning multiple values to multiple variables
  • 21. Python Literals • Literals are representations of fixed values in a program. They can be numbers, characters, or strings, etc. For example, 'Hello, World!', 12, 23.0, 'C', etc.
  • 22. Python Data Types • In computer programming, data types specify the type of data that can be stored inside a variable. For example,
  • 23. Python List Data Type • List is an ordered collection of similar or different types of items separated by commas and enclosed within brackets [ ]. For example, • Here, we have created a list named languages with 3 string values inside it.
  • 24. Access List Items • To access items from a list, we use the index number (0, 1, 2 ...). For example,
  • 25. Python Tuple Data Type • Tuple is an ordered sequence of items same as a list. The only difference is that tuples are immutable. Tuples once created cannot be modified. • In Python, we use the parentheses () to store items of a tuple. For example,
  • 26. Access Tuple Items • Similar to lists, we use the index number to access tuple items in Python . For example.
  • 28. Python Set Data Type • Set is an unordered collection of unique items. Set is defined by values separated by commas inside braces { }. For example,
  • 29. Python Type Conversion • In programming, type conversion is the process of converting data of one type to another. For example: converting integer data to string. • There are two types of type conversion in Python. • Implicit Conversion - automatic type conversion • Explicit Conversion - manual type conversion
  • 30. Python Implicit Type Conversion • Python automatically converts one data type to another. This is known as implicit type conversion. • Example 1: Converting integer to float
  • 31. Explicit Type Conversion • In Explicit Type Conversion, users convert the data type of an object to required data type. • We use the built-in functions like int(), float(), str(), etc to perform explicit type conversion. • This type of conversion is also called typecasting because the user casts (changes) the data type of the objects.
  • 32. Example 2: Addition of string and integer Using Explicit Conversion
  • 33. Key Points to Remember • Type Conversion is the conversion of an object from one data type to another data type. • Implicit Type Conversion is automatically performed by the Python interpreter. • Python avoids the loss of data in Implicit Type Conversion. • Explicit Type Conversion is also called Type Casting, the data types of objects are converted using predefined functions by the user. • In Type Casting, loss of data may occur as we enforce the object to a specific data type.
  • 34. Python Basic Input and Output • Python Output • In Python, we can simply use the print() function to print output. For example,
  • 35. Syntax of print() • object - value(s) to be printed • sep (optional) - allows us to separate multiple objects inside print(). • end (optional) - allows us to add add specific values like new line "n", tab "t" • file (optional) - where the values are printed. It's default value is sys.stdout (screen) • flush (optional) - boolean specifying if the output is flushed or buffered. Default: False
  • 36. Example 2: Python print() with end Parameter
  • 37. Example 3: Python print() with sep parameter
  • 38. Python input & output • While programming, we might want to take the input from the user. In python, we can use the input() function.
  • 39. Example: Print Python Variables and Literals
  • 41. Python Input • While programming, we might want to take the input from the user. In Python, we can use the input() function. • Syntax of input()
  • 44. Types of Python Operators 1. Arithmetic operators 2. Assignment Operators 3. Comparison Operators 4. Logical Operators 5. Bitwise Operators 6. Special Operators
  • 45. 1. Python Arithmetic Operators
  • 46. Example 1: Arithmetic Operators in Python
  • 47. 2. Python Assignment Operators • Assignment operators are used to assign values to variables. For example,
  • 49. 3. Python Comparison Operators
  • 51. 4. Python Logical Operators
  • 53. What is Name in Python? • Name (also called identifier) is simply a name given to objects. Everything in Python is an object. Name is a way to access the underlying object. • For example, when we do the assignment a = 2, 2 is an object stored in memory and a is the name we associate it with. We can get the address (in RAM) of some object through the built-in function id(). Let's look at how to use it.
  • 55. What is a Namespace in Python? • To simply put it, a namespace is a collection of names. • In Python, you can imagine a namespace as a mapping of every name you have defined to corresponding objects. • Different namespaces can co-exist at a given time but are completely isolated. • A namespace containing all the built-in names is created when we start the Python interpreter and exists as long as the interpreter runs. • This is the reason that built-in functions like id(), print() etc. are always available to us from any part of the program. Each module creates its own global namespace.
  • 56.
  • 57. Python Variable Scope • A scope is the portion of a program from where a namespace can be accessed directly without any prefix. • At any given moment, there are at least three nested scopes. 1. Scope of the current function which has local names 2. Scope of the module which has global names 3. Outermost scope which has built-in names
  • 58. Python Variable Scope • When a reference is made inside a function, the name is searched in the local namespace, then in the global namespace and finally in the built-in namespace. • If there is a function inside another function, a new scope is nested inside the local scope.
  • 59. Example of Scope and Namespace in Python • Here, the variable a is in the global namespace. Variable b is in the local namespace of outer_function() and c is in the nested local namespace of inner_function(). • When we are in inner_function(), c is local to us, b is nonlocal and a is global. We can read as well as assign new values to c but can only read b and a from inner_function().