1、python在命令行获取当前的路径

    import os

    os.getcwd()

    os.chdir(r"C:\Users\szlon\Desktop\pythonexer")

    os模块介绍

  2、在Python中\是转义符,\u表示其后是UNICODE编码,因此\User在这里会报错,在字符串前面加个r表示就可以了。

    Note:python中的字符串定义不是单引号吗?

  3、解答上面的Note问题,Python中的单引号、双引号和三引号

  4、python安装过程及怎么在windows命令行运行python文件

    python安装过程不叙述,记得勾选将python路径放入Windows运行环境。

     

    上面用到了两个Windows命令,CD转换运行路径。DIR显示当前路径下的所有文件。

  5、在python IDLE运行python文件

    import 文件名即可。

  6、教程中最开始的$符号是Linux命令行默认开始符号。

  7、获取List的长度。

     内置len函数。

     S1 = [1,2,3]

     S2 = [0,[1,2,3]]

        len(S1) = 3

        len(S2) = 2

     也就是list可以当任意类型当做一个元素来对待,即使它本身也是个list类型。

       元组合list都是序列。

  8、获取命令行输入

    直接input就好,是系统内置函数,不需要import。

      例:

 >>> mac_addr = input('请输入MAC地址:')
请输入MAC地址:10:23:45:67:89:10
>>> print(mac_addr)
10:23:45:67:89:10

  9、练习一早上

 Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> print('Hello World!')
Hello World!
>>> $python hello.py
SyntaxError: invalid syntax
>>> import os
>>> os.getcwd()
'C:\\Users\\szlon\\AppData\\Local\\Programs\\Python\\Python37'
>>> os.chdir("C:\Users\szlon\Desktop\pythonexer")
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
>>> os.chdir('C:\Users\szlon\Desktop\pythonexer')
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
>>> os.chdir(r"C:\Users\szlon\Desktop\pythonexer")
>>> os.getcwd
<built-in function getcwd>
>>> os.getcwd()
'C:\\Users\\szlon\\Desktop\\pythonexer'
>>> hello.py
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
hello.py
NameError: name 'hello' is not defined
>>> import hello
Hello World!
>>> a = 10
>>> print(a)
10
>>> print(type(a))
<class 'int'>
>>> a = 1.3
>>> print(a,type(a))
1.3 <class 'float'>
>>> a = True
>>> print(a,type(a))
True <class 'bool'>
>>> a = 'Hello!'
>>> print(a,type(a))
Hello! <class 'str'>
>>> s1 = (2,1.3,'love',5.6,9,12,False)
>>> print(s1,type(s1))
(2, 1.3, 'love', 5.6, 9, 12, False) <class 'tuple'>
>>> s2 = [true,5,'simle']
Traceback (most recent call last):
File "<pyshell#22>", line 1, in <module>
s2 = [true,5,'simle']
NameError: name 'true' is not defined
>>> s2 = [True,5,'simle']
>>> print(s2,type(s2))
[True, 5, 'simle'] <class 'list'>
>>> s3 = [1,[3,4,5]]
>>> print(s3,type(s3))
[1, [3, 4, 5]] <class 'list'>
>>> print(s3.count)
<built-in method count of list object at 0x0000021356CD5AC8>
>>> print(s3.count())
Traceback (most recent call last):
File "<pyshell#28>", line 1, in <module>
print(s3.count())
TypeError: count() takes exactly one argument (0 given)
>>> print(len(s3)
)
2
>>> print(len(s3))
2
>>> print(s1[0])
2
>>> print(s2[2])
simle
>>> print(s3[1][2])
5
>>> mac_addr = input('请输入MAC地址:')
请输入MAC地址:10:23:45:67:89:10
>>> print(mac_addr)
10:23:45:67:89:10
>>> print 1+9
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(1+9)?
>>> print (1+9)
10
>>> print (1.3 - 4)
-2.7
>>> print (3*5)
15
>>> print (4.5/1.5)
3.0
>>> print(3**2)
9
>>> print(10%3)
1
>>> print( 5 == 6)
False
>>> print (8.0 != 8.0)
False
>>> print( 3 < 3, 3 <= 3)
False True
>>> print(4 > 5, 4 >= 0)
False True
>>> print(5 in [1,3,5])
True
>>> print(True and True, True and False)
True False
>>> print(True or False)
True
>>> print(not True)
False
>>> print( 5==6 or 3 >=3)
True
>>>

  10、input输入的是字符串,怎么输入整数或者基本类型的数

   a = int(input('请输入一个整数'))

  11、一个求绝对值的小模块

 a = int(input('请输入一个数:'))

 if a >= 0:
a = a
else:
a = -a print('a的绝对值为:',a)

  12、1-100求和

 sum = 0;

 for i in range(101):
sum += i print(sum)

python_learn1的更多相关文章

随机推荐

  1. Auto-Test 要点纪录(一)

    1,select下拉框类型 使用工具可以看到html对应标签为<select>这类标签才是真正的下拉框类型就需要对应的方法,不能但看页面上的效果,有的做成了效果但其实不是select类型即 ...

  2. C++面试试题汇总1

    1.C和C++的主要区别是什么? 答:1.C++语言包括过程性语言部分和类部分,过程性语言部分与C并无本质的差别,类部分是C语言中所没有的,它是面向对象程序设计的主体. 2.程序设计方法上已从结构化程 ...

  3. Cocos2d-x 3.0 屏幕触摸及消息分发机制

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  4. IT行业是吃青春饭的吗?

    作者:杨中科 1.“it专业的学生太多了,而且就业压力很大”是吗?     现在各个大学为了赚钱拼命扩招,所以不仅IT专业的学生人比较多,而且其他专业的学生人数也比较多,“僧多粥少”就通常意味着就业压 ...

  5. 【Web API系列教程】1.2 — Web API 2中的Action Results

    前言 本节的主题是ASP.NET Web API怎样将控制器动作的返回值转换成HTTP的响应消息. Web API控制器动作能够返回下列的不论什么值: 1. void 2. HttpResponseM ...

  6. LeetCode Search in Rotated Sorted Array II -- 有重复的旋转序列搜索

    Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...

  7. cookie-小总结吧

    写入common.js文件,其他页面调用即可: //添加cookie值 function addcookie(name, value, days) { days = days || 0; var ex ...

  8. HDU 2242 考研路茫茫——空调教室(边双连通)

    HDU 2242 考研路茫茫--空调教室 题目链接 思路:求边双连通分量.然后进行缩点,点权为双连通分支的点权之和,缩点完变成一棵树,然后在树上dfs一遍就能得出答案 代码: #include < ...

  9. 使用python处理实验数据-yechen_pro_20171231

    整体思路 1.观察文档结构: - 工况之一 - 流量一28 - 测点位置=0 -测点纵断面深度-1 -该点数据Speedxxxxxxxx.txt -测点纵断面深度-2 -测点纵断面深度-3 -... ...

  10. NativeBase自定义组件样式

    http://nativebase.io/docs/v0.5.13/customize#themingNativeBaseApp 对于NativeBase中的组件,我们可以根据实际需要来进行自定义组件 ...