Course Python For Life 4 – Variables



As promised in the previous class, I present to you this lesson about variables. First we need to answer some questions. First, what’s a variable? The answer is: a variable is a space inside a memory, it save data and in programming languages, it also works for change the data inside it.

Python is an high-level language, an high-level language is nearer of programmer, or human language like English for example. Python is simple!

See below the variable declaration in languages like C, C++ or Java:


This is the variable declaration structure, but in Python, we don’t need of this structure. So, declare the type isn’t required, but we need to initializer the variable. Below, see the variable declaration structure in Python:


That’s enough, here we have the variable declaration in Python language. This structure is: variable_name = a_value, it can be a string too, or just a character. Test it in your interpreter, joyful!

If you want to use others formats like float for example, always specific it.

Note: you can declare many variables in an only line. There’s two ways to do this. See below:


But, when you want to declare them with different values, the structure is:


Now, to go on, you need to know the Lesson 3 content!

Python has a resource that work with input command to initialize an variable. This structure is below:


That’s, first is declared the variable and so, we have an input, but always with a type. See below how we impregnate it in a code:


Test it yourself! Use your creativity! Use others data types. Any doubt, comment this post.

In the next lesson, we’ll make some algorithms with all that we learned here. Share this course and lesson with your friends!

Well, that’s all folks!
See you later!

Comentários

More Famous Posts

Course C Initial 7th – Training with Math

Course C Initial – 3rd Variables Part. 1

Course Python For Life 3 – Input Command