码迷,mamicode.com
首页 > 编程语言 > 详细

python基础语法

时间:2020-04-10 00:35:12      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:声明   string   tuple   als   file   必须   mod   inf   tps   

1、字符串的常见操作:

技术图片

 

 

 2、print的常见操作

print 默认输出是换行的,如果要实现不换行需要在变量末尾加上 end=""

print(str1, end = " ")
print(str1, end = " ")

输出为:   runoob runoob 

3、导入操作

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

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

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

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

4、命令行参数

很多程序可以执行一些操作来查看一些基本信息,Python可以使用-h参数查看各参数帮助信息:

$ python -h
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
-c cmd : program passed in as string (terminates option list)
-d     : debug output from parser (also PYTHONDEBUG=x)
-E     : ignore environment variables (such as PYTHONPATH)
-h     : print this help message and exit

[ etc. ]

以上内容参考:https://www.runoob.com/python3/python3-basic-syntax.html

5、python的基本数据类型

Python 中的变量不需要声明。每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建。在 Python 中,变量就是变量,它没有类型,我们所说的"类型"是变量所指的内存中对象的类型。

(1)可以同时为多个变量赋值

1 a = b = c = 1
2 print(a, b, c)
3 a, b, c = 1, 2, 3
4 print(a, b, c)

结果为 :1 1 1

    1 2 3

(2)Python3 的六个标准数据类型中:

  • 不可变数据(3 个):Number(数字)、String(字符串)、Tuple(元组);
  • 可变数据(3 个):List(列表)、Dictionary(字典)、Set(集合)。

 

python基础语法

标签:声明   string   tuple   als   file   必须   mod   inf   tps   

原文地址:https://www.cnblogs.com/liliwang/p/12670498.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!