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ẻ !

Hòa mình vào lễ hội địa phương tại Kofu: Sắc màu văn hóa truyền thống Nhật Bản

Tham gia lễ hội địa phương là một cách để giải trí và hơn thế nữa, bản thân có thể học hỏi thêm tiếng Nhật và hiểu biết văn hóa Nhật Bản Gần trường Unitas - Kofu mình đang học cũng vậy. Lễ hội thờ đạo thần ở đây diễn ra hằng năm và năm nào cũng nhờ đến học sinh Unitas. Công việc được nhờ là mặc lễ phục, khiêng kiệu lên vai vừa đi vừa hô đi quanh quanh khu đó rồi về. Giữa lúc đi và về sẽ được nghỉ và cho uống nước ngọt. Lần đầu sang đây chơi mình cũng hí hửng lắm, mà do dự định là đi cũng mấy người đi đăng kí điện thoại cuối cùng không đăng kí được vì chưa đủ 20 tuổi. Mà trường hẹn 6h thì 6h30 cũng mới đi qua trường. Thật may là lúc đó mới đi. Ở đây lợi thế lùn mới được tôn vinh. Mấy ông cao to để kiệu lên vai đi tầm tiếng. Đã thế vừa đi người ta còn lắc kiệu (phong tục) nên khiêng được nửa đường ra hết. Còn mình 1m7 nên vai không chạm kiệu nên đứng vào cho đẹp đội hình. Hét là chính :P Cái áo cọc tay mặc từ lúc trưa (23 độ) đến 9h tối (10 độ) Được cái vui :D...

Phong Thần Web Gameplay

Trang chủ :  http://phongthan.360game.vn/ Thể loại : Web Games Game play : Game viết về thời Thương Chu đại chiến của trung quốc và có cùng tên với 1 tựa game mà VNG đã phát hành từ khá lâu nên thay vì gọi tên game là Phong Thần mình sẽ gọi là Phong thần Web để phân biệt. Hệ thống nhân vật tam giới thiết kế khá bắt mắt nhưng thực chất chỉ thay đổi về hình ảnh. Skill cũng vậy, người chơi có thể thay đổi dạng kĩ năng 3 loại nhờ pháp bảo. Vì vậy, công bằng là điều đương nhiên có trong game. Ngoài ra còn nhiều hệ thống tăng lực chiến khác mà mình cũng chả quan tâm làm gì vì nó cũng chỉ là tăng lực chiến mà thôi. Video chơi thử :