0% found this document useful (0 votes)
2 views26 pages

Python Basics

The document provides an overview of Python, a high-level programming language developed by Guido Van Rossum in 1991, highlighting its features, such as ease of learning and portability. It covers key concepts including variables, constants, data types, and the use of Integrated Development Environments (IDEs) for programming. Additionally, it explains the differences between mutable and immutable data types, as well as type conversion methods in Python.

Uploaded by

pinterestyyaazh
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)
2 views26 pages

Python Basics

The document provides an overview of Python, a high-level programming language developed by Guido Van Rossum in 1991, highlighting its features, such as ease of learning and portability. It covers key concepts including variables, constants, data types, and the use of Integrated Development Environments (IDEs) for programming. Additionally, it explains the differences between mutable and immutable data types, as well as type conversion methods in Python.

Uploaded by

pinterestyyaazh
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

Python Basics

Introduction to Python
• A ordered set of instruction to be executed by a computer
to carry out a specific task is called a program.
• As we know the computer can understand 0 and 1 that is
called low level language or machine language .
• The program we write that is written in high level language.
• To Convert that high level program into machine level we
need interpreter.
Python
• It is a high level language. It was developed by Guido Van Rossum in
Centrum Wiskunde and informatics,Netherlands released in 1991
• It is used to follow both procedural approach and
Object oriented approach programming.
Python get maximum popularity of the following
reason: 1. Easy to learn , read, maintain.
[Link] mode [Link] and Compatibility
4. Data base and Scalable
Key points about Python:
• Python is a high level language.
• It is free and open source language.
• It is an interpreted language as python program are executed by an
interpreter .
• Python is a case sensitive language.
Integrated Development Environment (IDE)
• An integrated Development Environment is a software application that
provide comprehensive facilities to computer programmers for software
development.
• An IDE normally consist of at least a source code editor build automation
tool and a debugger .
• Default IDE of Python is IDLE.
• Other IDE’s
[Link] Studio code
[Link]
[Link]
[Link]
[Link] +Pydev
File Extension
• .py Regular Python Script
• .ipynb jupyter notebook file
• .pyc Compiled script(bytecode)
• .pyo optimized pyc (Bytecode file)
• To write and run a python program we need to have a python
interpreter or we have to use any online python interpreter. The
interpreter is also called Python shell.
• The symbol >>> in the python prompt indicates that interpreter is
ready to take instruction.
Execution Mode
• Interactive Mode: Interactive Mode allow execution of individual
statement.

• Script Mode: Script mode allows us to write more than one


instruction
Comments
• Comments are used to add a remark or note in the source code.
• They are added with the purpose of making source code easy and
readable.
• Comments are not executed by the interpreter .It ignores the
comment.
• Comments Start with #
• Example:
• print(“Hello World”) # This statement print Hello world
Keywords and identifiers:
• The smallest unit of program is called Token.
Keywords:
The keywords and some predefined and reserved words in python that
have special meaning.
Keywords are used to define the syntax of coding.
The keywords are not used as an identifier function and variable name.
All the keywords in python are written in lower case except
True,False,None.
There are 35 keyword in python.
Identifiers
• The identifier is a name used to identify a variable, function,
class ,module etc.
• It differentiate one entity from another.
• Rules for Writing Identifiers:
• Identifiers can be combination of letter in lower case(a-z) or Upper
case(A-Z) or Digit(0-9) or Underscore(_)
• An identifier can not start with digit.
• Keywords are not used as identifiers.
• We can not use any special symbol like !,@,#,$ etc in identifiers.
• An identifiers can be of any length(But it is suggested that it should be
short and meaningful)
• No white space is allowed.
Variable and Constant
• A variable is named location used to store data in memory.
• It is helpful to think of variable as a container that holds data that can
be changed later in program.
Constants
• A constant is a type of variable whose value can not be changed.
• It is helpful to think of constants as containers that hold information
which can not be changed later.
• It is advised to use capital letters to denote constants in program.
Literals
• Literals is a raw data given in a variable or constant.
variable a= 7 Literals
In python there are various types of literals.
• Numeric Literals
• Special Literals
• String Literals
• Boolean Literals
Numerical Literals

• Numeric literals can belong to 3 different numerical types:


• Integer
• Float
• Complex

Note: Numeric Literals are immutable(unchanged)


• [Link] Literals : A string Literals is a sequence of characters
surrounded by quotes .We can use both single ,double and triple
quotes for a string.
• [Link] Literals: A Boolean literals can have any of the two values.
True or False.
• [Link] Literals: Python contain special [Link]
Introduction to Data Types:

• Data type are the classification and categorization of Data items.


• It represent the kind of values that tells what operation can be
performed on a particular data.
• Data types are broadly divided into three parts: [Link] Data type
[Link]
3. Sequence Type
Numeric Data Type
In python data type represent that data which has numeric
value.
Numeric value can be integer,floating point and complex
number.
These values are defined as int,float,complex class of python
respectively.
Types of Numeric Data Type:
• Integer:- This value is represented by int class.
• It contain positive or negative whole number (without fraction or
decimal).
• There is not limit to how long an integer value can be.

• Float:- This value is represented by float class.


.It is real number with floating point representation.
A floating point number is accurate up to 15 decimal point places.
Boolean Data Type
• Data types with one or two build in values “True or False”

• Note: True and False start with capital letter T and F otherwise
python throw an error.
Sequence Data Type
• In python sequence is the ordered collection of similar or different data types.
• Sequence allows to store multiple values in an organized and different fashion.
• There are several types of sequence types in python.
[Link] [Link] [Link]
[Link]: A string is a collection of one or more character put in a single quote, double
quote , Triple quote.
[Link]: It is very flexible as the item in the list do not need to be of the same type.
Note: List in python can be created by just placing the sequence inside the squre
brackets [ ].
• [Link]: Just like a list tuple is also an ordered collection of
python objects .The only difference between Tuple and List
is that tuple are immutable i.e Tuple can not be modified
after it is created.
• In python tuples are created by placing a sequence of
values separated by comma with or without the use of
parenthesis.

• NOTE: Creation of Python tuple without the use of


parenthesis () is known as “Tuple Packing”.
Mutable and immutable Data Types

• Some times we may require to change or update values of certain


variable used in program.
• Variable whose values can be changed after they are created and
assigned are called mutable.
• Variable whose values can be changed after they are created and
assigned are called immutable.

• Mutable Data Types: int, float, Boolean, Complex


number ,string ,Tuple , Set.
• Immutable Data Type: List , Dictionary.
Type Conversion & Type Casting:
• Type conversion is a method in which we convert or change the data of one
variable into another type.
• There are two type of type conversion in python
1. Implicit Type conversion [Link] Type conversion
Implicit Type Conversion: In Implicit type of conversion Python automatically
convert one data type to another data type this process does not need any user
involvement.
Data type conversion happen during compilation or run type.
Explicit Type Conversion:
In Explicit Type conversion users convert the data type of an object to required
data type.
This type of conversion is also called Type casting.
• Example:
>>> x=10.0
>>>int(x)
10

Point To Remember:
Python avoids the loss of data in implicit Type conversion.
In Explicit Type casting loss of data may occur as we enforce the
object to a specific data type.

You might also like