Notes Of Python Learning (Day 1)

(0)Introduction

Python is prized for its readability and simplicity. I am eager to learn this compiler language for such a long time. Fortunately, the vacation comes to the corner, which covers almost thirty days. At such an opportunity, I decide to add Python to my repertoire. I will keep updating my notes on the learning process.

(1)when comes to talk about the way to assign a variable

  1. We don’t need to declare the variable before we using it, which means it is much more convenient also it’s quite different from the way of JAVA or C++.

  2. The content of the variable is pretty flexible, in other words, we don’t need to tell Python what kind of value it is going to refer to. We can even reassign the value to refer to another sort of thing.

As for the comments, they all begin after “#” symbol

(2)How to write an " if " expression in Python?

First of all, let’s talk about the structure.

if William_weight < 70 :
	print("William is a handsome boy")

print("William should make a girlfriend")

In this part of the code, the William_weight symbol means the limitation.

What’s more, the: symbol means the beginning of a new code block. The subsequent line which is indented is part of this code block. Python use indentation to mark the beginning and end of the code block, while some other languages may use curly braces.

So when William_weight is positive, the sentence “William is a handsome boy” can be shown. While the later line is not in the code block, the expression will be shown without limitation.

(3) Operators Overloading

Operators Overloading is a kind of technical term that means redefining the defined operators with certain functions to complete more detailed and specific operations.

Let’s see a code snippet:

William_age = 19;
William_age = william_age * 2
print(William_age)

William_age = "19"
William_age = William_age*2
print(William_age)

and here is the result:

38
1919

when William_age refers to an integer, the * symbol simply holds the meaning of arithmetic multiply. While the William_age refers to a String, the * symbol means to get a version that’s been repeated that many times.

(4)Arithmetic

Python provides the basic arithmetic operators. And here are some points that we need to know.

  1. When we performing division, Python will show us a float
  2. The // operator gives us a result that’s rounded down to the next integer.
  3. The order of these operators is the same as the order of operations in Mathematics.
  4. When we are not able to figure out what a variable refers to, we can use type() to help us.
发布了9 篇原创文章 · 获赞 21 · 访问量 1351

猜你喜欢

转载自blog.csdn.net/weixin_44603756/article/details/104029421