A variable is like a container. Every variable has a value that has been assigned to it and whenever you use the variable the value that was assigned to it will actually be used. A variable's value can be changed dynamically through code and it will hold the last value that was assigned to it.
name = "John Doe"
Python allows you to assign more than one variable in a single line by separating their names and values with commas.
name, age, gender = "John", 12, "male"
In Python, there are a few rules that need to be followed when you're working with variables so that your code is easier to read and doesn't cause unnecessary errors.
The name of a variable can only contain numbers, letters, and underscores and must start with an underscore or a letter and not a number.
If you're variable name contains two words then join them together with a underscore because spaces shouldn't be used in variable names since adding a space makes them two different words.
Python comes with some restricted keywords that are used in programming and those words can't be used as the name of a variable since Python has assigned a special function to them already.
In Python, and other programming languages, constant variables are variables whose values cannot be changed once they have been declared.
Any variable whose name is written in all capital letters will be treated as a constant variable in Python.
VALUE_OF_PI = 3.14
Did you find this post informational? Share your thoughts in the comments and let me know where are you on your Python Journey. Don't forget to like and share if you found this helpful!
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3