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

Introduction of Python Programming

Python is a high-level, interpreted, object-oriented programming language known for its readability and ease of use. It supports various programming paradigms, has a large standard library, and allows for dynamic typing and modularity. The document also covers how to execute Python code using different methods and explains variables, expressions, and statements in Python.

Uploaded by

imchepan
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 views4 pages

Introduction of Python Programming

Python is a high-level, interpreted, object-oriented programming language known for its readability and ease of use. It supports various programming paradigms, has a large standard library, and allows for dynamic typing and modularity. The document also covers how to execute Python code using different methods and explains variables, expressions, and statements in Python.

Uploaded by

imchepan
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

Introduction

Python is a high-level, interpreted, object-oriented, and general-purpose programming language.


Python is a simple, easy to learn, syntax emphasizes readability and therefore reduces the cost
of program maintenance. We can think of Python as the "English" of programming languages—
it is designed to be easy for humans to read and write, while still being powerful enough to run
some of the world’s most complex technologies like NASA’s research systems and Netflix’s
recommendation engines. Python supports modules and packages, which encourages program
modularity (packages/modules in python) and code reuse. The Python interpreter and the
extensive standard library are available in source or binary form without any charge (no licensing
fee to use python) for all major platforms, and can be freely distributed (bundle python with your
own software). The Interpreter is the actual engine that "reads" your Python code and translates
it into instructions that the computer hardware can understand.

Key Characteristics of Python

• High level: In programming, "High" means closer to human language (English), while
"Low" means closer to machine language (1s and 0s). In such languages you only care
about logic; the language itself handles hardware, memory, and safety for you.
• Interpreted: Unlike languages like C programming, Python code is executed line-by-line.
This makes debugging much faster because the program stops the moment it hits an error.
However, overall execution will be slower as compared to C programming which is first
compiled then execution is completed without any interruption.
• Object oriented: In Python, everything including integers, strings, lists, and even
functions—is an object. For example, when you write x = 10, then x is an object
(instance) of the built-in ‘int’ class.
• Dynamically Typed: You do not need to tell the Python if a variable is a number or a string
(e.g., x = 5 instead of int x = 5). Here python itself figures it out automatically as ‘int’
data type during the execution.
• Multi-paradigm: It supports different styles of programming, including Object-Oriented
Programming (OOP), Procedural Programming, and Functional Programming.
• Large Standard Library: Python comes with a massive collection of pre-written code that
helps you to do everything for example from sending emails to connecting to web servers
without writing everything from scratch.
• Other characteristics includes: Python programming usually “free” a variable by itself by
using “garbage collector”, its script can execute over Windows as well as Linux, no concept
of using a variable’s memory address (pointer) as python completely hides it from
programmer, it simply gives an error when we try to access a non-existing variable in a
collection of values like list, and more characteristics.

How to execute a python program/ code/ script


1) Using the Interactive Shell: If you just want to test a single line of code quickly without saving
a file or test a small logic having few lines then you can use the interactive mode.

1. Open your command prompt or terminal.


2. Type “python” and press Enter key.
3. You will see >>>. Now you can type python code directly, and it will execute instantly
after you press Enter key.
4. Type exit() to close the interactive shell.

2) Using the Terminal or Command Prompt (Standard Way): This is the professional way to run
python scripts. You write your code in a text editor (like Notepad) and save it with a .py
extension ([Link]). After it

1. Open your Terminal (Linux/Ubuntu) or Command Prompt (Windows).


2. Navigate to the folder where your file is saved using the cd command.
3. Type python (or python3 on Linux/ Ubuntu) followed by your filename:
python [Link]
python3 [Link]

3) Using an IDE (Integrated Development Environment): An Integrated Development


Environment (IDE) can greatly enhance your coding experience, offering features like auto code
completion, easier debugging, and project management. There are different types of IDE are
available for python programming: PyCharm, VSCode (Visual Studio Code), Jupyter Notebook,
Spyder, Eclipse with PyDev plugins, and more.

4) Using Web-Based Notebooks: If you do not want to install anything on your computer, then
you can use Google Colab (Jupyter Notebooks). You just need a gmail id for it, and your entire
work will be saved in google drive.

Variables, Expressions and Statements

A variable is a reserved memory location to store values. In Python, you don't need to declare
the type of a variable; it is created the moment you first assign a value to it by using assignment
operator (=). Its syntax is:

VariableName = Value

There are some Naming Rules for a variable:

o It must start with a letter (alphabet) or underscore (_).


o Cannot start with a number or symbol.
o Can only contain alpha-numeric characters and underscores (A-z, 0-9, and _).
o In python, a variable name is a Case-sensitive: for example, age, Age, and AGE are
three different variables.

E.g. x = 5

x = 1.23

nm = “gehu”

nm = “dehradun”

Per10 = 78.43

Per = 12345.678912345

NOTE: to check the specific data type of a variable, you may use “type()” function. Its syntax
is
type(Value/VariableName)

For e.g. x = 5

nm = “gehu”

Per10 = 78.43

print(type(x))

print(type(nm))

print(type(Per10))

Output: <class 'int'>

<class 'str'>

<class 'float'>

There are only 3 primary data type exist in python: ‘int’, ‘float’,
and ‘str’. ‘int’, and ‘float’ are represented without any quotes,
however to represent and assign a string value we either use single
quote, double quote or triple quote

Python allows you to assign values to multiple variables in one line with the following
syntax:

VariableName1, VN2, VN3, ... = Value1, Value2, Value3, ...

e.g. v1, v2, v3 = 11, 1.23, "abc"

print("value is", v3)


Python also allows to assign the same value to multiple variables in one line:

VariableName1 = VN2 = VN3 = .... = Value

e.g. v1 = v2 = v3 = 100

This mean, v1, v2, and v3 all three variables will now hold value 100.

Expressions
An expression is a combination of values, variables, and operators that the Python interpreter
evaluates to produce a single value. So, if you type an expression in the interactive shell or in
jupyter notebook, the interpreter evaluates it and displays the result.

For example:

o 20 + 32 (Output: 52)
o x * 5 (If x is 5, Output: 25)
o len("Hello") (Output: 5)

Statements
A statement is a unit of code that the Python interpreter can execute. It represents an action or
a command. While an expression is a "value-producer," a statement is a "doer". Common
statements include:

• Assignment Statement: x = 10
• Print Statement: print(x)
• Conditional Statement: if x > 5:
• Import Statement: import math

You might also like