0% found this document useful (0 votes)
3 views7 pages

FOP 1

Python is a high-level, interpreted, and object-oriented programming language created by Guido van Rossum in 1991, emphasizing code readability and simplicity. It supports multiple programming paradigms and is widely used in various fields such as web development, data science, and artificial intelligence. The language features a broad standard library, interactive mode, and allows for variable creation and management, with distinctions between global and local variables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

FOP 1

Python is a high-level, interpreted, and object-oriented programming language created by Guido van Rossum in 1991, emphasizing code readability and simplicity. It supports multiple programming paradigms and is widely used in various fields such as web development, data science, and artificial intelligence. The language features a broad standard library, interactive mode, and allows for variable creation and management, with distinctions between global and local variables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

 History of Python:

Python is a widely used general programming language. It was initially designed by Guido van
Rossum in 1991 and developed by Python Software Foundation (PSF). It was mainly developed to emphasize
code readability, and its syntax allows programmers to express concepts in fewer lines of code. There is a fact
behind choosing the name Python. Guido van Rossum was reading the script of a popular BBC comedy series
"Monty Python's Flying Circus". He wanted to select a name which unique, sort, and a little mysterious. So he
decided to select Python after the "Monty Python's Flying Circus" for their newly created programming
language.

Python is a general-purpose, open-source, high-level, interpreted, and object-oriented programming language that
provides several libraries and frameworks. Python has gained popularity because of its simplicity, easy syntax, and
user-friendly environment. The usage of Python is as follows.

o Desktop Applications
o Web Applications
o Data Science
o Artificial Intelligence
o Machine Learning
o Scientific Computing
o Robotics
o Gaming
o Mobile Apps

Python programming language is being updated regularly with new features and supports. There are lots of
updates in Python versions, starting from 1994 to the current release. Python 3.12.1 is the latest stable version.

 What is Python?
Python is an object-oriented programming language that was developed by Guido vas Rossum and
first released in 1991. It is a multi-paradigm high-level general-purpose scripting language.
 Python supports multiple programming paradigms (models) like structured programming, object-
oriented programming, and functional programming. So it is called a multi-paradigm language.
 Python is user-friendly and can be used to develop application software like text editors, music
players, etc. so, it is called a high-level language.
 Python has several built-in libraries. There are also many third-party libraries with the help of all
these libraries we develop almost anything with Python. So, it is calledGeneral purpose language.
 Finally, python programs are executed line by line(interpreted). So, it is called a Scripting
Language.
Features:
1. Easy-to-learn: Python has few (32) keywords, a simple structure, and a clearly defined
syntax. This allows the student to pick up the language quickly.
2. Easy-to-read: Python code is more clearly defined and visible to the eyes.
3. Easy-to-maintain: Python's source code is fairly easy-to-maintain.
4. A broad standard library: Python's bulk of the library is very portable and cross-platform
compatible on UNIX, Windows, and Macintosh.
5. Interactive Mode: Python has support for an interactive mode which allowsinteractive
testing and debugging of snippets of code.
6. Portable: Python can run on a wide variety of hardware platforms and has the sameinterface on
all platforms.
7. 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.
8. Databases: Python provides interfaces to all major commercial databases.
9. 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.
10. Scalable: Python provides a better structure and support for large programs thanshell scripting.

 Python Interpreter and Interactive mode:


An interpreted language is a programming language whose implementations execute instructions directly and
freely, without previously compiling a program into machine-language instructions. In this language, once the
program is compiled it is expressed in the instructions of the target machine. Unlike compiled languages,
interpreted languages are executed line by line by an interpreter at runtime. This means the code is not translated
into machine language simultaneously. Instead, each instruction is converted and executed individually.
Python is an object-oriented programming language like Java. Python is called an interpreted
language. Python uses interchangeable code modules instead of a single long list of instructions that was
standard for functional programming languages. The standard implementation of Python is called “cpython”. It
is the default and widely used implementation of Python.

Compiler: A compiler is a program that translates a high-level language program intoa separate machine
language program. The machine language program can then be executed any time it is needed.
This is shown in the below figure.

Interpreter: The Python language uses an interpreter, which is a program that both translates and
executes the instructions in a high-level language program. As the interpreter reads each instruction in
the program, it converts it to machine language instructions and then immediately executes them. This
process repeats for every instruction in the program. This is shown in the below figure.
 Python Virtual Machine:

Python Virtual Machine (PVM) is a program that provides programming environment. The role of PVM is to
convert the byte code instructions into machine code so the computer can execute those machine code instructions
and display the output.
The interpreter converts the byte code into machine code and sends that machine code to the computer processor
for execution.

Internal working of Python

Python doesn’t convert its code into machine code, something that hardware can understand. It converts it into
something called byte code. So within Python, compilation happens, but it’s just not in a machine language. It is
into byte code (.pyc or .pyo) and this byte code can’t be understood by the CPU. So we need an interpreter called
the Python virtual machine to execute the byte codes.

 Variable:
Programs use variables to access and manipulate data that is stored in memory. A variableis a name that
represents a value in the computer’s memory. For example, a program thatcalculates the sales tax on a
purchase might use the variable name tax to represent thatvalue in memory. When a variable represents
a value in the computer’s memory, we say that the variable references the value.
Variable naming rules: Although we are allowed to make up our own names for variables, we must
follow these rules.
 A variable name starts with an alphabet or underscore (_).
 A variable name may consist of letters(A-Z), digits (0-9), and symbols.
 In symbols it supports only dollar sign ($) and underscore (_).
 A variable name can be of any length (either shorter or longer).
 A variable name should not be a keyword.
 A variable name should not allow white spaces.
 A variable should not allow duplicate names.
 A variable name is case-sensitive, the lower-case and upper-case letters are significant. (i.e., ‘total’ is
not the same as ‘Total’ and ‘TOTAL’).
In addition to following these rules, you should always choose names for your variables that indicate
what they are used for. For example, a variable that holds the temperature might be named
temperature, and a variable that holds a car’s speed mightbe named speed. You may be tempted to give
variables names like x and b2, but names like these give no clue as to what the variable’s purpose is.
Sample Variable Names

Creating Variables with Assignment Statements


We use an assignment statement to create a variable and make it reference a piece ofdata. Here is an
example of an assignment statement: age = 25

An assignment statement is written in the following general format:

Variable = expression
The equal sign (=) is known as the assignment operator. In the general format, the variable is the name
of a variable and an expression is a value, or any piece of code that results in a value. After an assignment
statement executes, the variable listed on the left side of the (=) operator will reference the value given
on the right side of the (=) operator.
Ex: (variable_demo1.py)
# This program demonstrates a variable.
room = 503

print('I am staying in room number', room)

Program output:
I am staying in room number 503
Variable Reassignment : Variables are called "variable" because they can reference different values
while a program is running. When you assign a value to a variable, the variable will reference that value
until you assign it a different value.
Ex: variable_demo2.py
# This program demonstrates variable reassignment.
# Assign a value to the dollars variable.
dollars = 2.75
print('I have', dollars, 'in my account.')

#Reassign dollars so it references a different value.


dollars = 99.95
print('But now I have', dollars, 'in my account!')

Program output:
I have 2.75 in my account.
But now I have 99.95 in my account!
Global and Local Variables in Python

Python Global variables are those which are not defined inside any function and have a global scope
whereas Python local variables are those which are defined inside a function and their scope is limited to that
function only. In other words, we can say that local variables are accessible only inside the function in which it
was initialized whereas the global variables are accessible throughout the program and inside every function.

Local Variables
Local variables in Python are those that are initialized inside a function and belong only to that particular
function. It cannot be accessed anywhere outside the function. Let’s see how to create a local variable.
Creating local variables in Python
Defining and accessing local variables

Python_Program_1:
def f():
# local variable
s = "I love Python"
print(s)

# Driver code
f()
Output
I love Python
Global Variables
These are those which are defined outside any function and which are accessible throughout the program, i.e.,
inside and outside of every function. Let’s see how to create a Python global variable.
Create a global variable in Python
Defining and accessing Python global variables.

Python_Program_2:
# This function uses global variable s
def f():
print("Inside Function", s)

# Global scope
s = "I love Python"
f()
print("Outside Function", s)
Output
Inside Function I love Python
Outside Function I love Python
The variable s is defined as the global variable and is used both inside the function as well as outside the
function.

 Keywords:
Each high-level language has its own set of predefined words that the programmer mustuse to write a
program. The words that make up a high-level programming language are known as keywords or
reserved words. Each keyword has a specific meaning, andcannot be used for any other purpose.

The Python keywords


and del from None True
as elif global nonlocal try
assert else if not while
break except import or with
class False in pass yield
continue finally is raise def
for lambda return

You might also like