Python learning- Variables, expressions and statements

齐昊焱
2023-12-01

Python小白的学习之路 Day1

  • 本文为作者学习python过程中所记录的笔记

  • Bg:作者已系统学习过半学年Java,学习Python资料为密歇根大学的公开课《Python for Everybody》,YouTube, Coursera 均有此视频。链接为 https://www.py4e.com/lessons 其中内置auto-grader,可以通过quiz检测自己的学习情况。此外,作者在学习过程中使用PyCharm练习Python

  • 第一次写此类文章,若文章中存在错误,欢迎各位指正,也期待与各位交流学习!

略过安装,配置过程,以及经典 print('Hello World!') —(原课程Chapter 1

Variables, expressions and statements (Chapter 2)

Constants

  • Fixed values such as numbers, letters and strings — values does not changed

Variables

  • Named place in the memory where programmer to store data

Reserved Words

  • class, return, is, etc.
  • Connot used them as variables / identifiers

Name Rules

  • Case Sensitive
  • Start with letters or underscore_
  • Must consist of letters, numbers, and underscores

Assignment Statements

  • Arrow nature: Right to left by “=”

Numeric Expressions

OperatorOperation
" + "Addition
" - "Subtraction
" * "Multiplication
" / "Division
" ** "Power
" % "Remainder

Operator Precedence Rules

Highest to lowest:

Parenthesis
Power
Multiplication
Addition
Left to Right

type() ask python what types of some numbers

Type Conversions

Using built-in functions int() and float()
  • Also can used them to convert between strings and integers. Importantly, string does not contain numeric characters will get an error.

Integer Division

  • Integer division produces a floating point result
>>> print(10 / 2)
5.0

User Input

  • Instruct Python to pause and read data from the user using the input() function
  • The input() function returns a string
nam = input('Who are you? ')
print('Welcome', nam)

Converting User Input

inp = input('Europe floor?')
usf = int(inp) + 1
print('US floor', usf)

Comments in Python

  • Anything after a # is ignored by Python
 类似资料:

相关阅读

相关文章

相关问答