Skip to main content

Learn Python #4 Variables & Data Types

  This tutorial, I want to talk to you about using variables in Python. Now in Python you are going to be dealing with a lot of data. So a lot of times in our program we are going to be working with all types of information and data and values. Sometime that data can be difficult to manage. So in Python we have this thing called a variable. And it's basically just a container where we can store certain data values. When we use a variable when we put those data values inside containers and make it a lot easier for us to work with and manage all of different data inside of our programs. So variables are extremely helpful and it's sort of like a core topic in Python that you're really going to want to know and master. So in this tutorial I will show you everything you need to know to get started with variables. We're going to look at what they are? Why they are useful and we'll look at the different types of variables and the different of data that we can store inside of variables.
  In python file I just have a very simple program and it's basically just printing some text out onto the screen. So this is a valid  Python program I can go ahead and Run this program and you can see down in the console. Every thing prints out and it looks great. We have an awesome little python program here
print("I am NgDinhNha")
print("I am 20 years old")
print("I am NgDinhNha")
print("I am 20 years old")
 Well, let's say that inside of our story I wanted to change the character's name and character's age. I'm going to have to go through and I'm going to have to manually change the name and age at every place inside of this story where it's mentioned. So in order to the character's name and age I had to manually go in and change it in all of places. It's going to work it's going to be updated in our program. But I'll notice that in order to make that change like I had to look through the entire program find it where that value was and change it. And this was only 4 lines of story. Imagine if I had a story that was like thousands of lines long. And we mentioned that the character's name and age like hundreds of times. We don't have to look through each one of those lines and manually change the character's name. And that is not a very good way for us to do this. Is's really not a good way for us to manage the data in our program right the character's name and age. So we can actually use a variable in order to store the character's name and character's age. And when we use that variable it'll make it a lot easier for us to put the character's name and age inside of our little program.
 Now it's going to go up above print statement and create a variable character_name and character_age then change it inside print statement.
character_name = "NgDinhNha"character_age = "20"
print("I am " + character_name + ".")
print("I am " + character_age + " years old")
print("I am " + character_name + ".")
print("I am " + character_age + " years old")
  So now when I run this program it's going to print out the same story they were print out before. But now I don't actually have to type in the character's name and character's age. I can just refer to this variable. And the cool thing about variables as if I wanted to change the character's name. Now all I have to do is change it up in variables.
character_name = "Nha"character_age = "30"
  So that's where variables can come in handy and this con be a really awesome way to control and manage the data that's inside of our programs. With variables you also can modify their values. For example, let's say that halfway through the story I wanted to change the character's name. I can actually assign a new line in the middle of program like
character_name = "Nha"character_age = "30"print("I am " + character_name + ".")
print("I am " + character_age + " years old")
character_name = "NgDinhNha"character_age = "20"print("I am  " + character_name + ".")
print("I am " + character_age + " years old")
and you'll see in the first part of the story and  the second part of the story are changed. That is actually awesome way you know a lot of times in these programs you're going to want to be modifying the values of variables.

  So finally I want to talk to you guys about the different types of data that we can store inside of these variables. I'm actually storing what are called strings in character_name and character_age. So a string is basically just plain text straight. So the data types of Python called a string and it's just basically going to store plain text. So you know any text that you would have like in a story early know someone's name. You can store inside of a string. there's also another type of data that we can store inside of python which is numbers. So an additional storing text we can also store. When we're storing a number we don't need these quotation marks. You only need quotation marks when you're storing a string. And in addition to using whole numbers I can also use decimal numbers. Python are going to be able to store that number as well. You can store all different types of numbers and we can also store what's called a boolean value. And a boolean value is essentially a true or false value. There's a lot of instances in programming where we're going to want to represent true or false data. For example,
character_name = "Nha"character_age = 30.5342is_male = True
  True of false value is maybe not something that you're used to dealing with like in the real world but in programming we're going to be using a true or false value all the time they're supper important.
  There are three basic types of data that we can work with it in python. There's a bunch of other types of data that we can use but I world say 99% of the time as a new user in a new programmer to python you're just going to be dealing with these three types of data. So those are the basic of the data also with variables

Comments

Popular Posts

7554 bất ngờ mở miễn phí tặng game thủ nhân dịp kỷ niệm 65 năm chiến thắng Điện Biên Phủ

  "Tiến tới kỷ niệm 65 năm chiến thắng Điện Biên Phủ(7/5/1954 - 7/5/2019) . Và cũng nhân dịp kỷ niệm 10 năm làm game của Hiker Games. Như đã hứa, xin được gửi tặng cộng đồng game thủ Việt Nam phiên bản 7554 hoàn toàn miễn phí. Các bạn có thể truy cập vào website http://www.7554.vn để download. Để đảm bảo không có hiểu nhầm nào, xin lưu ý, đây không phải là phiên bản làm lại của 7554.  Đây chỉ là phiên bản đã loại bỏ phần kiểm tra bản quyền để bất cứ ai cũng có thể tải về và trải nghiệm game. Chúc các bạn chơi game vui vẻ!"  Via 7554 Dưới đây là video hướng dẫn tải game:  Chúc các bạn chơi game vui vẻ !

Pokémon GO - Đột phá game Pokemon ngoài ĐỜI THỰC

Đã qua cái thời ngồi nhà ôm máy tính chơi game rồi! Những năm 1x của thế kỉ 21 đã xuất hiện Đột phá game ngoài ĐỜI THỰC và Pokemon Go là một ví dụ điển hình. Game dựa vào GPS để đảm bảo mọi người phải và chỉ có thể chơi khi cầm điện thoại ra đường. Cụm từ khóa Pokemon Go thực sự là một cụm từ hot lan đến tận Làng game Việt. Hiện game đang thử nghiệm trên 1 số quốc gia trong đó có Nhật Bản. Và mình cũng may mắn có 1 mail mời test thử game. Thật sự là một cảm giác mới lạ. Và một câu hỏi được đặt ra là liệu khi thế hệ game Thực tế ảo này có làm giảm lượng trẻ em ngồi nhà không hay lại tăng thêm lượng trẻ em đi bụi :))

Coinmarketcap X Solar (SXP) Learn Program with answer

 🔥Coinmarketcap X Solar (SXP) Learn Program🔥 💰Reward: 13.9 SXP[~20$] +50 diamonds (Random 5000 people) ✅Guide: 1. First signup here:  https://coinmarketcap.com/ 2. Then Signup here:  https://accounts.binance.me/en/register?ref=IWQEF0ZX  (KYC necessary) 3. Open this page and solve the quiz:  https://coinmarketcap.jotform.com/220947727078971 Answers: [Confirm once] Solar's governance is set up as: Ans: A fully decentralized autonomous organization (DAO) What innovations will Solar support within its ecosystem? Ans: All of the above How are node operators chosen? Ans: Based on votes by coin holders What is the native coin of the Solar network? Ans: SXP What happens to transaction fees? Ans: 90% of fees are burned. The remaining 10% is earned by node operators How does Solar help to ensure a sustainable blockchain future? Ans: Solar uses a highly energy-efficient consensus mechanism for its own blockchain and native coin. Solar's platform is Ans: Open source on G...