Python learning- Variables, expressions and statements

作者分享了学习Python的第一天经验,包括从Java转至Python的学习背景,使用密歇根大学的《PythonforEverybody》公开课资源,涉及变量、常量、表达式、语句、运算符优先级、类型检查、类型转换、整数除法及用户输入的介绍,并提到了使用PyCharm作为开发工具。
摘要由CSDN通过智能技术生成

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
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

J.Sampson

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值