py-helloWorld

#!/D/soft/python3/python.exe
# 注释
print("你好, 世界")
# 多行注释
'''
  一行
  两行
'''
# 多行注释
"""
  一行
  两行
"""

# 行与缩进

if True :
  print('True')
else :
  print('False')
 #   print('1') # 缩进不一致会报错

 # 多行语句
item_one = '1'
item_two = '2'
item_three = '3'
total = item_one + \
        item_two + \
        item_three
print(total)
total = [
  'item_one',
  'item_two',
  'item_three'
]
print(total)
'''
python中数字有四种类型:整数、布尔型、浮点数和复数。

int (整数), 如 1, 只有一种整数类型 int,表示为长整型,没有 python2 中的 Long。
bool (布尔), 如 True。
float (浮点数), 如 1.23、3E-2
complex (复数), 如 1 + 2j、 1.1 + 2.2j

'''

"""
Python 中单引号 ' 和双引号 " 使用完全相同。
使用三引号(''' 或 \"\"\")可以指定一个多行字符串。
转义符 \。
反斜杠可以用来转义,使用 r 可以让反斜杠不发生转义。 如 r"this is a line with \n" 则 \n 会显示,并不是换行。
按字面意义级联字符串,如 "this " "is " "string" 会被自动转换为 this is string。
字符串可以用 + 运算符连接在一起,用 * 运算符重复。
Python 中的字符串有两种索引方式,从左往右以 0 开始,从右往左以 -1 开始。
Python 中的字符串不能改变。
"""

print('this is a line with \n')
print("this is a line with \n")
print(r"this is a line with \n") # r=raw raw string,自动转义反斜杠
print("this is " + "a line with \n")
print("this is repeat " * 2)

str = 'string'
print(str)
sentence = "句子"
print(sentence)
paragraph = """
  段落
"""
print(paragraph)

# 字符串截取

str = '1234567890'
print(str)        # 输出字符串
print(str[0:-1])  # 输出第一个到倒数第二个的所有字符
print(str[0])     # 输出第一个字符
print(str[2:5])   # 输出第三个到第五个的所有字符
print(str[2:])    # 输出第三个后的所有字符
print(str[1:5:2]) # 输出第一个到第五个的字符,步长为2,即双数
print(str * 2)    # 输出两次字符串
print(str + '哈') # 输出字符串两次

# 等待用户输入
# input('\n\n 按下 enter 按键后推出。')

# 同一行显示多条语句,使用;分割
import sys; name = 'hjj' ; sys.stdout.write('hello ' + name + '\n')

'''
多个语句构成代码组
缩进相同的一组语句构成一个代码块,我们称之代码组。

像if、while、def和class这样的复合语句,首行以关键字开始,以冒号( : )结束,该行之后的一行或多行代码构成代码组。

我们将首行及后面的代码组称为一个子句(clause)。
'''

print('不换行1', end='')
print('不换行2', end='')
print('换行')

""" 
在 python 用 import 或者 from...import 来导入相应的模块。

将整个模块(somemodule)导入,格式为: import somemodule

从某个模块中导入某个函数,格式为: from somemodule import somefunction

从某个模块中导入多个函数,格式为: from somemodule import firstfunc, secondfunc, thirdfunc

将某个模块中的全部函数导入,格式为: from somemodule import *
"""

# import sys
# for i in sys.argv:
#   print(i)
# print('\n python 路径为:', sys.path)

from sys import path
print('path: ', path)



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值