d7c0d863 1676987272842
d7c0d863 1676987272842
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:
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)
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.
The bool()
function