0% found this document useful (0 votes)
70 views59 pages

d7c0d863 1676987272842

This document provides an introduction to the Python programming language. It discusses that Python is a high-level, general-purpose, interpreted programming language that is easy to learn and can be used for a wide range of applications. It explains that Python code is written in plain text files and interpreted at runtime rather than compiled. Indentation through whitespace is used to indicate code blocks rather than braces. The document also covers installing Python on different operating systems and provides examples of working with Python in both interactive and script modes.

Uploaded by

ankita shreepad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views59 pages

d7c0d863 1676987272842

This document provides an introduction to the Python programming language. It discusses that Python is a high-level, general-purpose, interpreted programming language that is easy to learn and can be used for a wide range of applications. It explains that Python code is written in plain text files and interpreted at runtime rather than compiled. Indentation through whitespace is used to indicate code blocks rather than braces. The document also covers installing Python on different operating systems and provides examples of working with Python in both interactive and script modes.

Uploaded by

ankita shreepad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 59

UNIT 1

Introduction to python
Dr Yasir | 26899 | Sports and Cultural Coordinator
 Python is a high-level, general-purpose,
interpreted programming language
What is python?
 Python is a high-level programming language
that makes it easy to learn.
High-level
 Python doesn’t require you to understand the
details of the computer in order to develop
programs efficiently
 Python is a general-purpose language. It means that
you can use Python in various domains including:
Web applications
Big data applications
Testing
General-
purpose Automation
Data science, machine learning, and AI
Desktop software
Mobile apps
 The targeted language like SQL which can be used for
querying data from relational databases.
 Python is an interpreted language. To develop a
Python program, you write Python code into a
file called source code.
 To execute the source code, you need to
convert it to the machine language that the
Interpreted computer can understand. And the Python
interpreter turns the source code, line by line,
once at a time, into the machine code when the
Python program executes.
 Compiled languages like Java and C# use a
compiler that compiles the whole source code
before the program executes.
 Python increases your productivity. Python
allows you to solve complex problems in less
time and fewer lines of code. It’s quick to make
a prototype in Python.
Why Python  Python becomes a solution in many areas
across industries, from web applications to
data science and machine learning.
 Python is quite easy to learn in comparison
with other programming languages. Python
syntax is clear and beautiful.
 Python has a large ecosystem that includes lots
of libraries and frameworks.
 Python is cross-platform. Python programs can
run on Windows, Linux, and macOS.
Why Python  Python has a huge community. Whenever you
get stuck, you can get help from an active
community.
 Python developers are in high demand.
 Easy to use
 Runs across different platforms
 Interpreted language
 Extensive Support Libraries.
Advantages  Free and Open Source
 Object oriented
 User-friendly Data Structures
 Embeddable
 Python is relatively easy to learn
language as it uses simpler syntax and
shorter codes.
Easy to use  Reading and writing codes in Python is
much like reading and writing regular
English statements.
 Programs written in python can run on
variety of platforms like
Runs across windows,Linux/Unix,Mac OS
different X,supercomputers,smart phones etc.
platforms  In other words python is a cross platform
language
 Python is an interpreted language.
 This means that every time a program is
Interpreted
run, its interpreter runs through the code
language
and translates it into machine-readable
byte code
 When you install Python, you get
everything you need to do real work.
 Python provides a large standard library
Extensive which contain code for various purposes
Support like regular expressions, emails, web
Libraries. pages, databases, network connections,
GUI developments and many more.
 So, you don’t have to write the complete
code for that manually.
 Python Language is freely available.
Free and Open  You can also download its source code,
Source
make changes to it, and even distribute it
 Python supports both the procedural and
Object object-oriented programming
oriented paradigms.
 Python has built-in list and dictionary
User-friendly data structures which can be used to
Data construct fast run-time data structures.
Structures  Python is an embeddable language. You
can put your Python code in your source
Embeddable code of a different language, like C++
 Web and Internet Development
 Scientific and Numeric
 Education
Applications of  Desktop GUIs
python  Software Development
 Business Applications
Install Python
 First, download the latest version of Python
on Windows
from the download page.
 Second, double-click the installer file to launch
the setup wizard.
 In the setup window, you need to check the
Add Python 3.8 to PATH and click Install Now
to begin the installation.
 To verify the installation, you open the Run window and type cmd
and press Enter

Verify the
installation
 In the Command Prompt, type python command as follows:

 to exit the program, you type Ctrl-Z and press Enter.


 It’s recommended to install Python on macOS
using an official installer. Here are the steps:
• First, download a Python release for macOS.
Install Python • Second, run the installer by double-clicking the
on macOS installer file.
• Third, follow the instruction on the screen and
click the Next button until the installer
completes.
 Before installing Python 3 on your Linux
distribution, you check whether Python 3 was
Install Python already installed by running the following
on Linux command from the terminal:
 python3 –version
 If you see a response with the version of Python, then
your computer already has Python 3 installed.
 Otherwise, you can install Python 3 using a
package management system
 For example, you can install Python 3.10 on
Ubuntu using apt (Advanced Packaging Tool ::
command-line tool : ):
 sudo apt install python3.10
• Interactive Mode(Immediate Mode)
Working in • Script mode
python
 In interactive mode there is a shell
between the user and the operating
system which reads a Python statement,
Working in evaluates the result of that statement,
interactive and then prints the result on the screen.
Mode  Then, it loops back to read the next
statement.
 With the Python interactive interpreter it
is easy to check Python commands.
 First, launch the Python IDLE program:

Python IDLE
 If you need to write a long piece of
Python code and save all the commands
in the form of program file and want to
see all output lines together then
Working in interactive mode is not recommended.
script mode  Script mode is the way to go in such
cases.
 In script mode, You write your code in a
text file then save it with a .py extension
which stands for "Python".
 To work in scrip mode, follow the following
steps:
1.Open IDLE as done in interactive mode.
 2. Click File->New
3. A new window will be opened, type the
How to work in commands or program in this window
script mode
 Now to save the file, go to File->save and
then choose the desired location and
save the file.
 Remember that “save as type ” should be
python files.
 By doing this, our file will be saved with
“.py” extension.
Now to run the file,
Go to Run->run module
 And you will see the output
 Python provides no braces to indicate
blocks of code for class and function
definitions or flow control.
Line and  Blocks of code are denoted by line
Indentation in indentation, which is rigidly enforced.
Python
 Python provides no braces to indicate
blocks of code for class and function
definitions or flow control. Blocks of
code are denoted by line indentation,
which is rigidly enforced
Example 1 (No
Error)
Example 2
(Error)
Example 3 (No
Error)

Thus, in Python all the continuous lines indented with


same number of spaces would form a block.
 Whitespace and indentation
Python  Comments
Syntax  Continuation of statements
 If you’ve been working in other
programming languages such as Java,
C#, or C/C++, you know that these
Whitespace languages use semicolons (;) to separate
and the statements.
indentation  However, Python uses whitespace and
indentation to construct the code
structure
At the end of each line, you don’t see any semicolon to terminate
the statement.
And the code uses indentation to format the code
 In Python, a single-line comment begins with a
hash (#) symbol followed by the comment. For
example:
Comments
# This is a single line comment in Python
 Python uses a newline character to separate
statements. It places each statement on one
line.
Continuation  However, a long statement can span multiple
of statements lines by using the backslash (\) character.
 Identifiers are names that identify variables,
functions, modules, classes, and other objects
in Python.
Identifiers  Python identifiers are case-sensitive.
 In addition, you cannot use Python keywords
for naming identifiers.
 Some words have special meanings in Python. They are called
keywords

Keywords
 Python uses single quotes ('), double quotes ("),
triple single quotes (''') and triple-double quotes
(""") to denote a string literal.
 The string literal need to be surrounded with
String literals the same type of quotes.
 For example, if you use a single quote to start a
string literal, you need to use the same single
quote to end it
examples of
string literals
 When you develop a program, you need to
manage values, a lot of them. To store values,
you use variables.

variable in
Python
 The = is the assignment operator.
 The value can be anything like a number, a
Creating string, etc., that you assign to the variable.
variables  For eg
 a = 10
1. Variable names can contain only letters,
numbers, and underscores (_). They can start
with a letter or an underscore (_), not with a
Rules for number.
Naming 2. Variable names cannot contain spaces. To
variables separate words in variables, you use
underscores for example sorted_list.
3. Variable names cannot be the same as
keywords, reserved words, and built-in
functions in Python.
 A string is a series of characters.
 in Python, anything inside quotes is a string.
And you can use either single or double quotes.
Python string
 When you place the string literals next to each
other, Python automatically concatenates
them into one string.
Concatenating
Python strings
To concatenate two string variables, you use the
operator +:
 Python supports
Python 1. Integers
Numbers 2. Floats
3. complex numbers
 The integers are numbers such as -1, 0, 1, 2,
and 3, .. and they have type int.
 You can use Math operators like +, -, *, and / to
form expressions that include integers. For
Integers example:
 Any number with a decimal point is a
floating-point number.
 The term float means that the decimal point
can appear at any position in a number.

Floats
 A complex number is created from real
numbers.
 >>>z = 3 + 2j
Complex
 When you check its type, you’ll confirm that it’s
number
indeed a complex number:
 >>>type(z)
<class 'complex'>
 When a number is large, it’ll become difficult to
Underscores read. For example:
in numbers count = 10000000000
 To make the long numbers more readable, you can
group digits using underscores, like this:
 count = 10_000_000_000
 In programming, you often want to check if a
condition is true or not and perform some
actions based on the result.
 To represent true and false, Python provides
Python you with the boolean data type. The boolean
Boolean data value has a technical name as bool.
type  The boolean data type has two values: True and
False.
 Note that the boolean values True and False
start with the capital letters (T) and (F).
 When you compare two numbers, Python
returns the result as a boolean value.

 Also, comparing two strings results in a boolean value:


 To find out if a value is True or False, you use
the bool() function. For example

The bool()
function

When a value evaluates to True, it’s truthy. And


if a value evaluates to False, it’s falsy.
 Sometimes, you may want to store values in
variables. But you don’t want to change these
values throughout the execution of the
Python program.
Constants  To do it in other programming languages, you
can use constants. The constants are like
variables but their values don’t change during
the program execution.
 The bad news is that Python doesn’t support
constants.
Thank you

You might also like