Chapter 2 - Variables and Data Types: A B "Harry" C
Chapter 2 - Variables and Data Types: A B "Harry" C
a=30
b=”Harry”
c=71.22
Copy
Variable – Container to store a value
Data Types:
Primarily there are the following data types in Python:
1. Integers
2. Floating point numbers
3. Strings
4. Booleans
5. None
a = 71 #Identifies a as
class<int>
b = 88.44 #Identifies b as
class<float>
name = “Harry” #Identifies name as
class<Str>
Copy
Rules for defining a variable name: (Also applicable to other identifiers)
Operators in Python
The following are some common operators in Python:
type function is used to find the data type of a given variable in Python.
a = 31
type(a) #class<int>
b = “31”
type(b) #class<str>
Copy
A number can be converted into a string and vice versa (if possible)
There are many functions to convert one data type into another.
Str(31) # ”31” Integer to string conversion
input() function
This function allows the user to take input from the keyboard as a string.
Suppose if a user enters 34, then this 34 will automatically convert to “34”
string literal.