Assigning Values to Variables and Basic Data Types in Python
Introduction
In this section, we will cover the following topics:
Assigning values to variables
Basic data types in Python
Assigning Values to Variables
In Python, we can assign values to variables using the = sign. For
example:
X=5
Name = “John”
In the above example, x is assigned the value 5 and name is assigned the
string “John”.
Variables in Python do not have a specific type, and can hold values of
different types. For example:
X=5
X = “Hello”
In the above example, x is first assigned the value 5 (an integer), and then
it is assigned the string “Hello”. This is perfectly valid in Python and is
known as dynamic typing.
Basic Data Types
Python has several built-in data types, including:
Integers (int): e.g. 5, -3, 0
Floating point numbers (float): e.g. 3.14, 0.0, -0.5
Strings (str): e.g. “Hello”, “world”, “”
Lists (list): e.g. [1, 2, 3], [“a”, “b”, “c”]
Introduction
In this section, we will cover the following topics:
Assigning values to variables
Basic data types in Python
Assigning Values to Variables
In Python, we can assign values to variables using the = sign. For
example:
X=5
Name = “John”
In the above example, x is assigned the value 5 and name is assigned the
string “John”.
Variables in Python do not have a specific type, and can hold values of
different types. For example:
X=5
X = “Hello”
In the above example, x is first assigned the value 5 (an integer), and then
it is assigned the string “Hello”. This is perfectly valid in Python and is
known as dynamic typing.
Basic Data Types
Python has several built-in data types, including:
Integers (int): e.g. 5, -3, 0
Floating point numbers (float): e.g. 3.14, 0.0, -0.5
Strings (str): e.g. “Hello”, “world”, “”
Lists (list): e.g. [1, 2, 3], [“a”, “b”, “c”]