0% found this document useful (0 votes)
5 views

Final PYTHON NOTES

Python is an object-oriented, high-level programming language known for its readability and simplicity, created by Guido Van Rossum and released in 1991. It features an Integrated Development Environment (IDLE) that supports both interactive and script modes for coding, along with various data types and operators. Python's dynamic typing and flexible variable assignment make it accessible for developers, while its extensive libraries and third-party IDEs enhance its functionality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Final PYTHON NOTES

Python is an object-oriented, high-level programming language known for its readability and simplicity, created by Guido Van Rossum and released in 1991. It features an Integrated Development Environment (IDLE) that supports both interactive and script modes for coding, along with various data types and operators. Python's dynamic typing and flexible variable assignment make it accessible for developers, while its extensive libraries and third-party IDEs enhance its functionality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

INTRODUCTION TO PYTHON

Python is an object-oriented, high-level, interpreted


programming language. Python programs consist of
lines of code, which are executed one by one by the
interpreter.
It emphasizes code readability and uses indentation to define code
blocks. Python was created by Guido Van Rossum. The language
was released in 1991.

Some of the features that make Python so popular are as follows:

 Easy to Learn
 It has a very simple syntax. 
 It is case -sensitive language
  It is platform independent programming
language
 It is free to use and even free for commercial
products.


Integrated Development Environment
An IDE is a comprehensive software that contains the tools to
write, compile, debug the code and display the output.
Each programming language have exclusive IDEs that can be used
for writing lines of code.
There are IDEs that can be installed on a computer, as well as the
ones that can be accessed on the web.
The IDE used for Python is known as IDLE.

IDLE ( Python IDE)


IDLE stands for Integrated Development and Learning
Environment
IDLE is an official IDE that comes bundled with Python.
It provides both interactive and script modes within the same
interface.
You can type and execute code in the interactive shell, and you
can also write and run scripts in separate windows.
IDLE supports syntax highlighting and basic debugging features.

Different Modes of IDLE Python


When starting with Python programming, it's essential to
understand the different modes that IDLE Python (Interactive
Development Environment for Applications in Learning) offers.
IDLE Python provides a user-friendly environment for writing,
editing, and running Python code.
Here are the different modes you'll encounter:
Interactive Mode (>>>):
This is the simplest way to experiment with Python code.
In this mode, you can type Python expressions or statements
directly, and Python will execute them immediately.
The Python prompt >>> indicates that you're in interactive mode.
Example:

Script Mode:
In script mode, you write your Python code in a file with a .py
extension using a text editor.
You save the file and then execute it using the Python interpreter.
This mode is suitable for writing longer programs and reusing
code.
Example:

Other IDEs (e.g., PyCharm, Visual Studio Code):


There are third-party IDEs that offer more advanced features for
Python development.
These IDEs provide features like code auto-completion, advanced
debugging, and integration with version control systems. PyCharm
and Visual Studio Code are popular choices for Python
development.
CODING IN PYTHON
Print Command
The print() command/function is used to display output in Python.
It can display text, variables, and expressions.
Multiple items can be printed using commas.
Example:

Input Command
The input() command/function is used to receive user input in
Python. It displays a prompt to the user and waits for input.
The input is stored as a string, so you might need to convert it to
the desired data type.
Example:

Python Comments
Comments can be used to explain Python code.
Comments can be used to make the code more readable.
Comments can be used to prevent
execution when testing code.
Comments starts with a #, and Python
will ignore them
Python Variables
A variable is a named memory location where we can store any
value.

Python has no command for declaring a variable.

A variable is created the moment you first assign a value to it.

Python allows you to assign


values to multiple variables
in one line.

You can assign the same value to multiple variables in one line.

Rules for Python variables:

A variable name must start with a letter or the underscore


character. It cannot start with a number.

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)

A variable name cannot be any of the Python keywords.


Keywords are the reserved words that have some special meaning
to the language compiler.

We cannot use a keyword as variable name, function name or any


other identifier.

They are used to define the syntax and structure of the Python
language In Python, keywords are case sensitive.

Eg: False, class, finally, return

You can get a list of available keywords by using help()


Data types are means to identify the type of data and associated
operations of handling it.

In Python, Data Types are essential building blocks that enable developers
to create flexible and efficient applications. Python offers a rich set of built-
in Data Types catering to various data representations and computations.

Since everything is an object in Python programming, data types are


actually classes and variables are instances (object) of these classes. Each
Data Type has its unique properties, constraints, and operations associated
with it.

Variables are not explicitly declared in Python, thanks to the language’s


dynamic typing. Instead, this programming language infers the Data Type
of a variable based on the value assigned to it.

You can get the data type of a variable with the type() function.

Two of the most commonly used datatypes in Python are:

Integer: Integers are whole numbers, both positive and negative, without
any fractional part.

Eg : x = 10 y = -25 z=0

Float: Floats are numbers with decimal points, enabling the representation
of real numbers. They are used for more precise mathematical
calculations, including scientific and financial computations.

Eg : pi = 3.14159 radius = 2.5

Boolean: Booleans represent one of two values: True or False. t is used to


represent two possible states and they are true or false, on or off, yes or
no, etc.

Eg : flag = true flag =false


OPERATORS IN PYTHON

An operator is a symbol that tells the computer what operations are


to be performed on the variables/constants. The variable upon
which an operator performs an operation are known as operands.

Arithmetic Operators:
They are used to perform arithmetical operations on the
operands.
+ Addition - Subtraction * Multiplication

% Modulus ** Exponentiation / Division


(remainder)

Modulus operator (%) is used to find remainder when two


numbers are divided.

Eg : int a = 5%2; then a will store 1

Python Indentation
Indentation refers to the spaces at the beginning of a code line.
Where in other programming languages the indentation in code is
for readability only, the indentation in Python is very important.
Python uses indentation to indicate a block of code.

Concatenation
Combining a string, text or the other data in a series without any
gaps is known as concatenation. To display both text and variables
in same line, we can concatenate them using comma.
Eg : print (“ My name is”, name)

You might also like