Beginner python Tutorial 3

Variables

Variables are used to store information in Python, and that information can be anything—a line of text, the name of a person, or a number. Several data types can be stored in a variable, which we will talk about later in this course.

Examples of variables:



In this code, age is the variable, and the equal sign shows it has been assigned the value of 22, so anytime we mention age in our code or print the variable age, we know it is going to output the value it has stored, which is 22. Print the variable age and run your code to see the results below in the Python interpreter.







We can also do some more coding in Python Interpreter. 













As you can see above, if you want to change the value of the variable from 22 to 33, just assign the variable to your preferred value and print it. The red syntax you see with the # sign is a comment.

Let's look at some feasible rules before we end this tutorial.

  • In our next toturial we are going to do some exercises on variables good luck!



No comments:

Post a Comment

Python Programming Tutorial 15

 Error Handling Anytime we work with user input, we should make sure not only the data is valid and within the range we want, like what we d...