Example is from Python shell
100 is a constant
Counter is a variable
We will talk more about types later in this module
There are multiple number types, which we’ll see soon
This is just a very brief intro to all data types mentioned in previous slide
Things after a # are comments
List if a sequence of things
Tuple is also a sequence of things
Difference between list and tuple: a list is mutable (can be modified) while a tuple is immutable (cannot be modified)
Disctionary is a bunch of key-value pairs
The ‘type’ function returns the datatype of the variable
Type of a variable = the type of data it is storing currently
The notion of variable type in Python is different in Python versus C/C++/Java. Python is dynamically typed which means that the variable can hold different types of data during its lifetime. However, C/C++/Java are statically types, which means that the variable can hold only one type of data during its entire lifetime
When a constant is passed to the type function, Python internally creates a temporary variables and passes that to the function
Float is another of number type
x can be assigned any value.
There is no type tied to variable x it can be assigned any value we like.
An operation like 10 + “10” would work in a weakly typed language like perl, it would do the conversions implicitly
Python does not allow this. You have to type conversion yourself.
1var : cannot start a variable name with integer
1var : cannot start a variable name with integer
myVar == myvar : variables are case sensitive
On accessing a non existing variable python throws NameError