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

Lecture 2 Python Self notes

Python is a versatile programming language created by Guido van Rossum in 1991, used in various fields such as web development, AI, and scientific applications. Its features include easy syntax, portability, and support for multiple programming paradigms, making it accessible for beginners. Python programs can be executed interactively, from files, or as scripts, and it supports various data types and operators.

Uploaded by

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

Lecture 2 Python Self notes

Python is a versatile programming language created by Guido van Rossum in 1991, used in various fields such as web development, AI, and scientific applications. Its features include easy syntax, portability, and support for multiple programming paradigms, making it accessible for beginners. Python programs can be executed interactively, from files, or as scripts, and it supports various data types and operators.

Uploaded by

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

Programming Language 1

Python3 programming
Lecture 2
What is Python?
• Python is a popular programming
language. It was created by Guido van
Rossum, and released in 1991.
• It is used for:
• Web development (server-side),
• Game Development
• Scientific and Numeric Applications
• Artificial Intelligence and Machine
Learning
• Desktop GUI
• Software Development
• Education programs and training courses
Why python?
• Python works on different platforms (Windows, Mac, Linux,
Raspberry Pi, etc).
• Python has a simple syntax like the English language.
• Python has syntax that allows developers to write programs with
fewer lines than some other programming languages.
• Python runs on an interpreter system, meaning that code can be
executed as soon as it is written. This means that prototyping can
be very quick.
• Python can be treated in a procedural way, an object-oriented
way or a functional way.
Python Features
• Easy-to-learn − Python has few keywords, simple structure, and a clearly defined syntax. This allows a student to pick
up the language quickly.
• Easy-to-read − Python code is more clearly defined and visible to the eyes.
• Easy-to-maintain − Python's source code is fairly easy-to-maintain.
• Interactive Mode − Python has support for an interactive mode which allows interactive testing and debugging of
snippets of code.
• Portable − Python can run on a wide variety of hardware platforms and has the same interface on all platforms.
• Extendable − You can add low-level modules to the Python interpreter. These modules enable programmers to add to
or customize their tools to be more efficient.
• Databases − Python provides interfaces to all major commercial databases.
• GUI Programming − Python supports GUI applications that can be created and ported to many system calls, libraries
and windows systems, such as Windows MFC, Macintosh, and the X Window system of Unix.
• Scalable − Python provides a better structure and support for large programs than shell scripting.
Python Execution Model
There are several ways in which you can run a
Python program, including:

1. Interactively using the Python interpreter


Running
Python 2. Stored in a file and run using the Python
Programs command

3. Run as a script file specifying the Python


interpreter to use within the script file

4. From within a Python IDE (Integrated


Development Environment) such as PyCharm.
Interactively Using the Python
Interpreter
• This uses the Python REPL (named after Read
Evaluate Print Loop style of operation).
• To run the Python REPL, Python must have been
installed onto the computer system you are using
Running a Python File
• We can of course store the Python
commands into a file. This creates a
program file that can then be run as an
argument to the python command.
Executing a Python Script

A script is a stand-alone file that can be run directly without the need to (explicitly) use the
python command.

This is done by adding a special line to the start of the Python file that indicates the Python
command (or interpreter) to use with the rest of the file.

This line must start with '#!' and must come at the start of the file.

To convert the previous section’s file into a Script we would need to add the path to the python
interpreter.

Here path refers to the route that the computer must take to find the specified Python
interpreter (or executable).
Executing a Python Script
Installing Python on a Windows PC
Setting up the path of python

• The easiest way to find


this is to type 'envir' into
the Windows search
box.
Setting up the path of python cont.
First program
Writing a
program in
python IDE
Reserved
words
• Python accepts single ('), double (") and
triple (''' or """) quotes to denote string
literals, as long as the same type of quote
Quotation in starts and ends the string.
Python • The triple quotes are used to span the string
across multiple lines.
Comments
• Python has five standard
data types −
• Numbers
• Python supports three different
Standard Data numerical types −
• int (signed integers)
Types • float (floating point real values)
• complex (complex numbers)
• String
• List
• Tuple
• Dictionary
Data types built-in by default in python
Assigning
Values to
Variables
Multiple Assignment
A variable name must start with a letter or
the underscore character

A variable name cannot start with a


number
Variable
naming A variable name can only contain alpha-
numeric characters and underscores (A-z,
0-9, and _ )

Variable names are case-sensitive (age,


Age and AGE are three different variables)
Python
numbers
Python
Strings
String split
Counting String
Replacing
• For more details in string methods visit:
Strings • https://docs.python.org/3/library/stdtypes
.html#string-methods
Different
string
operations
Different
string
operations
output.
Type Conversion
• You can convert from one type to another with
the int() ,float() dna ,complex() :sdohtem
Random
Number
Operators
• Python language supports the following types of
operators −
• Arithmetic Operators
• Comparison (Relational) Operators
• Assignment Operators
• Logical Operators
• Bitwise Operators
• Membership Operators
• Identity Operators
Arithmetic
Operators
Arithmetic
Operators cont.
Comparison (Relational) Operators
Assignment Operators
Logical Operators
Bitwise operators
Python Identity Operators
Identity operators compare the memory locations of two objects.
Membership operators
• Python’s membership operators test for membership in a sequence,
such as strings, lists, or tuples.
Converting
to float
• A Beginners Guide to Python 3 Programming
• http://www.mediafire.com/file/29t7cy8c1i2pay
h/A+Beginners+Guide+to+python3+programmin
g.pdf/file
• Python GUI programming with Tkinter
• http://www.mediafire.com/file/yqjv956ryrgcu51
/Python_GUI_Programming_with_Tkinter_Deve.
References pdf/file
• https://www.w3schools.com/python/default
.asp
• https://www.tutorialspoint.com/python3/in
dex.htm
• https://docs.python.org/3/library/
Thanks

You might also like