【Python】我感觉我什么都忘了Day1

难以置信的是我已经完全看不懂以前写的代码了;要学Anaconda和Tensor的话得赶紧捡起来;

还有就是搞定自动机以后就能更愉快地摸鱼了;

昨天简单看看,发现连标识符都不记得了;

确认是阿尔兹海默症的青年了.

【选书部分】先看这个

随便看看,就差不是30天XX了

【首先是基本的】

2 ** 4 ## 2 ** 4 就是 2^4

【数据类型】

表 1-2 常见数据类型
数据类型 例子
整型 -2, -1, 0, 1, 2, 3, 4, 5
浮点型 -1.25, -1.0, - -0.5, 0.0, 0.5, 1.0, 1.25
字符串 'a', 'aa', 'aaa', 'Hello!', '11 cats'

##非常普通,这些还记得

Python 程序也可以有文本值,称为“字符串”,或strs(发音为“stirs”)。总是
用单引号(')包围住字符串(例如'Hello'或'Goodbye cruel world!'),这样Python 就
知道字符串的开始和结束。甚至可以有没有字符的字符串,称为“空字符串”。第4
章更详细地解释了字符串。

##好像有这回事

>>> 'Alice' + 42
Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>

【待解】为什么字符串不能加数字呢?不能看成是ASC2码么?

【变量相关】

这个还记得

变量名是区分大小写的。这意味着,spam、SPAM、Spam 和sPaM 是4 个不
同的变量。变量用小写字母开头是Python 的惯例。

本书的变量名使用了驼峰形式, 没有用下划线。也就是说, 变量名用
lookLikeThis,而不是looking_like_this。一些有经验的程序员可能会指出,官方的
Python 代码风格PEP 8,即应该使用下划线。我喜欢驼峰式,这没有错,并认为PEP
8 本身“愚蠢的一致性是头脑狭隘人士的心魔”:
“一致地满足风格指南是重要的。但最重要的是,知道何时要不一致,因为有
时候风格指南就是不适用。如果有怀疑,请相信自己的最佳判断。”

哈哈哈哈哈哈哈

>>> str(0)
'0'
>>> str(-3.14)
'-3.14'
>>> int('42')
42
>>> int('-99')
-99
>>> int(1.25)
1
>>> int(1.99)
1
>>> float('3.14')
3.14
>>> float(10)
10.0

这转义也太爽了

【IDE相关】

以前用的是VS和Pycharm,这次直接用Anaconda自带的Spyder好了

# -*- coding: utf-8 -*-
"""
Created on Mon Oct 29 09:48:28 2018

@author: Lenovo
"""

print('Hello Python!')
print("hello Python!")
print('input Num test!')
myIntNum = input()
print('input is ' + myIntNum)
print('input is ' + str(myIntNum))
print('length of input is ',end = "")
print(len(myIntNum))

输出:


runfile('E:/PythonLearning/untitled2.py', wdir='E:/PythonLearning')
Hello Python!
hello Python!
input Num test!

1551
input is 1551
input is 1551
length of input is 4

Py还是莫名舒服啊,用一种MATLAB或者R的感觉(我已经是R的形状了)

上面需要纠正

print('Hello Python!')
print('input Num test!')
myIntNum = input() ##myIntNum<-1551
print(type(myIntNum))
print(type(int(myIntNum)))
runfile('E:/PythonLearning/0ramTest.py', wdir='E:/PythonLearning')
Hello Python!
input Num test!

1551
<class 'str'>
<class 'int'>

默认输入铁打的str,还有就是环境变量乱瘤

自动补全主要还是自己按Tab

~突然好困,啊~~~~~~~~~~

runfile('E:/PythonLearning/0ramTest.py', wdir='E:/PythonLearning')
1551

reset

Once deleted, variables cannot be recovered. Proceed (y/[n])? y

runfile('E:/PythonLearning/0ramTest.py', wdir='E:/PythonLearning')
Traceback (most recent call last):

  File "<ipython-input-6-1dba797abbf8>", line 1, in <module>
    runfile('E:/PythonLearning/0ramTest.py', wdir='E:/PythonLearning')

  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "E:/PythonLearning/0ramTest.py", line 8, in <module>
    print(myIntNum)

NameError: name 'myIntNum' is not defined

为什么变量用完还会有啊,是Spyder的特性吗,这也太R了

【看两眼内存】

# True
a = 1
b = 1
print(a is b)

# True
a = "good"
b = "good"
print(a is b)

# True
a = "very good morning"
b = "very good morning"
print(a is b)

# False
a = []
b = []
print(a is b)

这么神奇的吗,这个几乎啥都不记得了

先备个份,等下看完函数引用这些再来看内存;

Python的内存管理

再摸合适了,书签2.7.8,P37

猜你喜欢

转载自blog.csdn.net/baidu_34331290/article/details/83537092