SlideShare a Scribd company logo
Prepared by Prof. Rushikesh Kolhe, Asst. Professor, Department of Civil Engineering, SCOE, Kopargaon.
UNIT II
DATA TYPES AND VARIABLES IN PYTHON
Introduction data types and variables, types of Data types and variables
Python is a dynamically typed language, which means you don't have to declare the type of a
variable when you create one. This flexibility allows Python to be very user-friendly and easy
to work with. Below, we delve into the details of data types and variables in Python.
2.1 Introduction to Data Types and Variables
Variables in Python are more than just names bound to objects. They serve as references to
objects stored in memory. Unlike some other programming languages, Python does not require
explicit declaration to reserve memory space. The declaration happens automatically when you
assign a value to a variable. The equal sign (=) is used to assign values to variables.
Dynamic Typing
Python is dynamically typed, which means the type of variable is determined at runtime, not in
advance. This provides flexibility but requires understanding how types can change.
Variable Naming Conventions
• Names can start with a letter or an underscore, not with a number.
• Names can contain letters, numbers, and underscores.
• Python is case-sensitive; thus, Variable is different from variable.
Variables are essentially the names you give to computer memory locations which are used to
store values in a programming language. In Python, variables are created the moment you
assign a value to them.
Data Types are an important concept in programming. They are the classification or
categorization of data items. They represent the kind of value that tells what operations can be
performed on a particular data. Since everything is an object in Python programming, data
types are actually classes and variables are instance (object) of these classes.
2.2 Types of Data Types in Python
Python has various standard data types that are used to define the operations possible on them
and the storage method for each of them. Python data types can be broadly classified into:
1. Numeric Types: Integers, Floating point numbers, and Complex numbers.
1. Integers (int): Represent whole numbers, positive or negative, without decimals,
of unlimited length. Commonly used in counting, indexing, and operations that
require precision without fractional parts.
• Integers (int): Whole numbers, positive or negative, without decimals of
unlimited length.
Prepared by Prof. Rushikesh Kolhe, Asst. Professor, Department of Civil Engineering, SCOE, Kopargaon.
2. Floating Point Numbers (float):
Represent real numbers and contain one or more decimals. Suitable for
measurements, scientific calculations, and any operation that requires fractional
numbers.
Precision might be an issue for very high precision requirements due to the way
floating-point numbers are stored.
• Floating Point Numbers (float): Numbers, positive or negative, containing one
or more decimals.
3. Complex Numbers (complex):
Written with a "j" as the imaginary part (x + yj), where x and y are floats.
Used in fields requiring complex number calculations such as signal processing,
engineering, and specific branches of mathematics.
• Complex Numbers (complex): Written with a "j" as the imaginary part: x + yj.
2. Sequence Types: Lists, Tuples, and Strings.
1. Lists (list):
Ordered and changeable (mutable) collections, allowing duplicate members.
Versatile for storing a sequence of objects that may need to be altered during the
program lifecycle, such as adding, removing, or changing elements.
2. Tuples (tuple):
Ordered collections like lists, but unchangeable (immutable).
Suitable for fixed data sets. They can be used as keys in dictionaries or as
elements of sets, where immutability is necessary.
3. Strings (str):
Ordered sequences of characters, making them immutable.
Used for text representation, including processing and manipulation of textual
data like names, messages, and outputs.
3. Mapping Type: Dictionary.
• Dictionary (dict): Unordered, changeable, and indexed collections, written
with curly brackets. Dictionaries have keys and values.
4. Set Types: Sets and Frozen Sets.
• Set (set): Unordered and unindexed collections, written with curly brackets.
However, unlike dictionaries, they are unordered collections of unique
elements.
• Frozen Set (frozenset): Immutable and hashable version of a set.
5. Boolean Type (bool): Represents True or False values and is used to perform logical
operations.
6. Binary Types: Binary, Bytearray, Memoryview.
• Bytes (bytes): Immutable sequence of bytes.
• Bytearray (bytearray): Mutable sequence of bytes.
• Memoryview (memoryview): Memory view object of the byte data.
Variables in Python
Variables in Python are created by a simple assignment operation, with the variable name on
the left, the assignment operator =, and the value on the right. Python infers the type of the
variable based on the value assigned to it.
• Dynamic Typing: Python allows you to reassign variables to different data types.
• Naming Conventions: Variable names can be short (a, x, y) or descriptive (age,
car_speed, total_volume). However, they must start with a letter or an underscore,
cannot begin with a number, and are case-sensitive.
Prepared by Prof. Rushikesh Kolhe, Asst. Professor, Department of Civil Engineering, SCOE, Kopargaon.
2.3 Mutable vs Immutable Data Types
• Mutable: Their content can be changed without changing their identity. Examples
include lists, dictionaries, and sets.
• Immutable: Their content cannot be changed once they are created. Examples include
integers, floats, strings, and tuples.
Summary
Understanding data types and variables is fundamental in Python as it affects how data can be
manipulated and stored. Each data type in Python is designed with a specific purpose in mind,
offering a wide range of functionalities to perform various operations on data efficiently.
Variables in Python are easy to declare and use, promoting a cleaner and more readable
codebase.

More Related Content

PDF
4. Data Handling computer shcience pdf s
PPTX
Values and Data types in python
PPTX
Python variables and data types.pptx
PPTX
Python_Buildin_Data_types_Lecture_8.pptx
PPTX
Cthhis_is_cybersecurty_and_cyber_sxec.pptx
PPTX
Data types in python lecture (2)
PDF
Python Programminng…………………………………………………..
PPTX
2. Values and Data types in Python.pptx
4. Data Handling computer shcience pdf s
Values and Data types in python
Python variables and data types.pptx
Python_Buildin_Data_types_Lecture_8.pptx
Cthhis_is_cybersecurty_and_cyber_sxec.pptx
Data types in python lecture (2)
Python Programminng…………………………………………………..
2. Values and Data types in Python.pptx

Similar to Programming in Civil Engineering_UNIT 2_NOTES (20)

PPTX
introduction to python,datatypes,operators
PDF
CS-XII Python Fundamentals.pdf
PPTX
Python Data Types in depth description .pptx
PDF
Free Complete Python - A step towards Data Science
PPTX
python
PDF
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
PPTX
Introduction to Python Programming Language
PPTX
009 Data Handling class 11 -converted.pptx
PPTX
IOT notes,................................
PDF
The python fundamental introduction part 1
PDF
Python for beginners
PPTX
Data_Types_in_Python_Presentation (1).pptx
PPTX
009 Data Handling .pptx
DOCX
unit 1.docx
PDF
E-Notes_3720_Content_Document_20250107032323PM.pdf
PPTX
Python Data-Types
PDF
Introduction to Python - Jouda M Qamar.pdf
PPTX
Introduction to Programming.pptx ok ok ok
PPTX
introduction to python,datatypes,operators
CS-XII Python Fundamentals.pdf
Python Data Types in depth description .pptx
Free Complete Python - A step towards Data Science
python
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
Introduction to Python Programming Language
009 Data Handling class 11 -converted.pptx
IOT notes,................................
The python fundamental introduction part 1
Python for beginners
Data_Types_in_Python_Presentation (1).pptx
009 Data Handling .pptx
unit 1.docx
E-Notes_3720_Content_Document_20250107032323PM.pdf
Python Data-Types
Introduction to Python - Jouda M Qamar.pdf
Introduction to Programming.pptx ok ok ok
Ad

More from Rushikesh Kolhe (20)

PDF
Smart Cities Planning and Management UNIT6 NOTES
PDF
Smart Cities Planning and Management UNIT5 NOTES
PDF
Smart Cities Planning and Management UNIT4 NOTES
PDF
Smart Cities Planning and Management UNIT3 NOTES
PDF
Smart Cities Planning and Management UNIT2 NOTES
PDF
Smart Cities Planning and Management UNIT1 NOTES
PDF
Programming in Civil Engineering_UNIT 3_NOTES
PDF
Programming in Civil Engineering_UNIT 1_NOTES
PPTX
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
PPTX
Why Python in required in Civil Engineering
PPTX
Introduction to Python Programming in Civil Engineering
PPTX
Smart city Developments in India
PPTX
Framework for Smart City
PPTX
E governance.pptx
PPTX
Human Resource Information System
PPTX
Introduction to TQM
PDF
Fuzzy Logic
PDF
Human Resource Management: Training and Development (HRM)
PPTX
Work Breakdown Structure (WBS)
PDF
Materials Codification and Classification
Smart Cities Planning and Management UNIT6 NOTES
Smart Cities Planning and Management UNIT5 NOTES
Smart Cities Planning and Management UNIT4 NOTES
Smart Cities Planning and Management UNIT3 NOTES
Smart Cities Planning and Management UNIT2 NOTES
Smart Cities Planning and Management UNIT1 NOTES
Programming in Civil Engineering_UNIT 3_NOTES
Programming in Civil Engineering_UNIT 1_NOTES
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
Why Python in required in Civil Engineering
Introduction to Python Programming in Civil Engineering
Smart city Developments in India
Framework for Smart City
E governance.pptx
Human Resource Information System
Introduction to TQM
Fuzzy Logic
Human Resource Management: Training and Development (HRM)
Work Breakdown Structure (WBS)
Materials Codification and Classification
Ad

Recently uploaded (20)

PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
Digital Logic Computer Design lecture notes
PDF
composite construction of structures.pdf
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
PPT on Performance Review to get promotions
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Sustainable Sites - Green Building Construction
PPTX
Construction Project Organization Group 2.pptx
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPT
Project quality management in manufacturing
PPT
Mechanical Engineering MATERIALS Selection
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
CH1 Production IntroductoryConcepts.pptx
Digital Logic Computer Design lecture notes
composite construction of structures.pdf
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
CYBER-CRIMES AND SECURITY A guide to understanding
PPT on Performance Review to get promotions
Operating System & Kernel Study Guide-1 - converted.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Sustainable Sites - Green Building Construction
Construction Project Organization Group 2.pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Project quality management in manufacturing
Mechanical Engineering MATERIALS Selection
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
UNIT 4 Total Quality Management .pptx
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx

Programming in Civil Engineering_UNIT 2_NOTES

  • 1. Prepared by Prof. Rushikesh Kolhe, Asst. Professor, Department of Civil Engineering, SCOE, Kopargaon. UNIT II DATA TYPES AND VARIABLES IN PYTHON Introduction data types and variables, types of Data types and variables Python is a dynamically typed language, which means you don't have to declare the type of a variable when you create one. This flexibility allows Python to be very user-friendly and easy to work with. Below, we delve into the details of data types and variables in Python. 2.1 Introduction to Data Types and Variables Variables in Python are more than just names bound to objects. They serve as references to objects stored in memory. Unlike some other programming languages, Python does not require explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables. Dynamic Typing Python is dynamically typed, which means the type of variable is determined at runtime, not in advance. This provides flexibility but requires understanding how types can change. Variable Naming Conventions • Names can start with a letter or an underscore, not with a number. • Names can contain letters, numbers, and underscores. • Python is case-sensitive; thus, Variable is different from variable. Variables are essentially the names you give to computer memory locations which are used to store values in a programming language. In Python, variables are created the moment you assign a value to them. Data Types are an important concept in programming. They are the classification or categorization of data items. They represent the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes. 2.2 Types of Data Types in Python Python has various standard data types that are used to define the operations possible on them and the storage method for each of them. Python data types can be broadly classified into: 1. Numeric Types: Integers, Floating point numbers, and Complex numbers. 1. Integers (int): Represent whole numbers, positive or negative, without decimals, of unlimited length. Commonly used in counting, indexing, and operations that require precision without fractional parts. • Integers (int): Whole numbers, positive or negative, without decimals of unlimited length.
  • 2. Prepared by Prof. Rushikesh Kolhe, Asst. Professor, Department of Civil Engineering, SCOE, Kopargaon. 2. Floating Point Numbers (float): Represent real numbers and contain one or more decimals. Suitable for measurements, scientific calculations, and any operation that requires fractional numbers. Precision might be an issue for very high precision requirements due to the way floating-point numbers are stored. • Floating Point Numbers (float): Numbers, positive or negative, containing one or more decimals. 3. Complex Numbers (complex): Written with a "j" as the imaginary part (x + yj), where x and y are floats. Used in fields requiring complex number calculations such as signal processing, engineering, and specific branches of mathematics. • Complex Numbers (complex): Written with a "j" as the imaginary part: x + yj. 2. Sequence Types: Lists, Tuples, and Strings. 1. Lists (list): Ordered and changeable (mutable) collections, allowing duplicate members. Versatile for storing a sequence of objects that may need to be altered during the program lifecycle, such as adding, removing, or changing elements. 2. Tuples (tuple): Ordered collections like lists, but unchangeable (immutable). Suitable for fixed data sets. They can be used as keys in dictionaries or as elements of sets, where immutability is necessary. 3. Strings (str): Ordered sequences of characters, making them immutable. Used for text representation, including processing and manipulation of textual data like names, messages, and outputs. 3. Mapping Type: Dictionary. • Dictionary (dict): Unordered, changeable, and indexed collections, written with curly brackets. Dictionaries have keys and values. 4. Set Types: Sets and Frozen Sets. • Set (set): Unordered and unindexed collections, written with curly brackets. However, unlike dictionaries, they are unordered collections of unique elements. • Frozen Set (frozenset): Immutable and hashable version of a set. 5. Boolean Type (bool): Represents True or False values and is used to perform logical operations. 6. Binary Types: Binary, Bytearray, Memoryview. • Bytes (bytes): Immutable sequence of bytes. • Bytearray (bytearray): Mutable sequence of bytes. • Memoryview (memoryview): Memory view object of the byte data. Variables in Python Variables in Python are created by a simple assignment operation, with the variable name on the left, the assignment operator =, and the value on the right. Python infers the type of the variable based on the value assigned to it. • Dynamic Typing: Python allows you to reassign variables to different data types. • Naming Conventions: Variable names can be short (a, x, y) or descriptive (age, car_speed, total_volume). However, they must start with a letter or an underscore, cannot begin with a number, and are case-sensitive.
  • 3. Prepared by Prof. Rushikesh Kolhe, Asst. Professor, Department of Civil Engineering, SCOE, Kopargaon. 2.3 Mutable vs Immutable Data Types • Mutable: Their content can be changed without changing their identity. Examples include lists, dictionaries, and sets. • Immutable: Their content cannot be changed once they are created. Examples include integers, floats, strings, and tuples. Summary Understanding data types and variables is fundamental in Python as it affects how data can be manipulated and stored. Each data type in Python is designed with a specific purpose in mind, offering a wide range of functionalities to perform various operations on data efficiently. Variables in Python are easy to declare and use, promoting a cleaner and more readable codebase.