In this chapter, I am going to show you all how to create a python variable.
Python variable does not have a fixed type which means you can actually change the variable type by first assigning it to a number but later changing it to a string, Python will not complain about this!
aname = "Hello, World" print(aname) # Hello World aname = 10 print(aname) # 10
If you want to use the Python variable which is outside of a function within that function itself then you will need to declare it as a global variable within the function.
value = 5 def print_value(): global value value += 1 print(value) # increase the value of a variable by 1 which is equal to 6
You can specify the data type of a variable with casting but basically, it is the same outcome as before if you change it later to a string because Python does not have type safety like Java or C!
value = int(10) print(value) # 10 value = 13 print(value) # 13 value= "Hello World!" print(value) # Hello World!
That is it, I will start to load you with a complex tutorial but as always let us starts it with this easy one first!