PyCharmEdu中的基础教程——Introduction to Python

目录 

python介绍

1.介绍

1.1第一个程序

1.2注释

2.变量(Variables)

3.字符串(Strings)

4.数据结构(Data structures)

5.条件表达式(Condition expressions)

6.循环(Loops)

7.函数(Functions)

8.类与对象(Classes and objects)

9.模块和包(Modules and packages)

10.文件输入/输出(File input/output)


1.介绍

1.1第一个程序hello_world.py

print("Hello, world! My name is dudu")
1.2注释(comments)

# This is the comment for the comments.py file
print("Hello!")  # this comment is for the second line

print("# this is not a comment")
# new comment
2.变量

常用的数字数据类型(Common used numeric data types)

Name Notation Declaration e.g.
Integers int a = 10
Floating float b = 3.14
Complex complex c = 1 + 2j
String str d = 'Python'
  • 备注:
  • 在Python 2.7中,int与另一个int运算将导致int结果。 但是,一个浮点运算与int会导致浮点数。
  • 在Python 3.x中,int与另一个int运算将导致浮点数。

2.1定义变量

a = b = 2  # This is called a "chained assignment". It assigns the value 2 to variables "a" and "b".
print("a = " + str(a))   # We'll explain the expression str(a) later in the course. For now it is used to convert the  variable "a" to a string.
print("b = " + str(b))

greetings = "greetings"
print("greetings = " + str(greetings))
greetings = 2333
print("greetings = " + str(greetings))
2.2未定义的变量

variable = 1
print(other_variable)
2.3变量类型

number = 9
print(type(number))   # print type of variable "number"

float_number = 9.0
print(type(float_number))
2.4变量类型转变

number = 9
print(type(number))   # print type of variable "number"

float_number = 9.0
print(float_number)
print(int(float_number))

2.5算术运算符(arithmetic operator)

number = 9.0        # float number

result = number / 2

remainder = number % 2

print("result = " + str(result))
print("remainder = " + str(remainder))

2.6赋值(Assignments)

number = 9.0
print("number = " + str(number))

number -= 2
print("number = " + str(number))

number += 5

print("number = " + str(number))

2.7逻辑算子/布尔操作符(boolean oper
  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值