Python学习[00]

来源:互联网 发布:诺兰蝙蝠侠三部曲知乎 编辑:程序博客网 时间:2024/06/07 06:33

[00]Learn Python——Python Syntax


1.Variables

Creating web apps, games, and search engines all involve storing and working with different types of data. They do so using variables. A variable stores a piece of data, and gives it a specific name.

spam = 5

2.Booleans

A boolean is like a light switch. It can only have two values. Just like a light switch can only be on or off, a boolean can only be True or False.

a = Trueb = False

3.Whitespace for indentation

In Python, whitespace is used to structure code. Whitespace is important, so you have to be careful with how you use it.Usually we use 4 blank space or 2 blank space**or**1 Tab

def spam():    eggs = 12    return eggsprint spam()

4.Single Line Comments/Multi-line Comments

The # sign is for comments. A comment is a line of text that Python won’t try to run as code. It’s just for humans to read.
For multi-line comments, you can include the whole block in a set of triple quotation marks:

"""Sipping from your cup 'til it runneth over,Holy Grail."""

5.Math

addition = 72 + 23subtraction = 108 - 204multiplication = 108 * 0.5division = 108 / 9exponentiation = 2 ** 3modulo = 3 % 2

6.Bringing It All Together

  • Variables, which store values for later use
  • Data types, such as numbers and booleans
  • Whitespace, which separates statements
  • Comments, which make your code easier to read
  • Arithmetic operations, including +, -, , /, *, and %