python学习记录(一)
1.打印操作
>>> print('hello')
hello
>>> print(1+2)
3
2.字符串操作
①
print(1+2+'')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
print(1+2+'')
TypeError: unsupported operand type(s) for +: 'int' and 'str' #整数与字符串不能相加
②
>>> print('hello'*7)
hellohellohellohellohellohellohello #整数能与字符串相乘
>>> print('hello'*7.0)
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
print('hello'*7.0)
TypeError: can't multiply sequence by non-int of type 'float' #浮点数不能与字符串相乘
3.类型转化
①字符串转化为整数
>>> print(int("") + int(""))
5
②输入数据+类型转化+数据相加
>>> float(input("num1:"))+float(input("num2:"))
num1:30
num2:2
32.0
③关于报错
int(input("num1:"))
num1:2.0
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
int(input("num1:"))
ValueError: invalid literal for int() with base 10: '2.0' #输入为浮点数,与int不符
④例子
>>> float(""*int(input("enter a number:")))
enter a number:2
210210.0 #210210转化为浮点型
4.变量
变量赋初值+变量的删除+输入变量值
>>> a=1
>>> print(a)
1
>>> print(a+3)
4
>>> print(a*2)
2
>>> a="hello"
>>> print(a*2)
hellohello
>>> del a
>>> print(a)
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
print(a)
NameError: name 'a' is not defined
>>> a = input("number:")
number:2
>>> print(a)
2
5.赋值运算符
>>> a=1
>>> a+=2
>>> print(a)
3
>>> str1="abc"
>>> str1+="def"
>>> print(str1)
abcdef
与c语言相似,但无++等运算符
练习戳下
python学习记录(一)的更多相关文章
- Python学习记录day6
title: Python学习记录day6 tags: python author: Chinge Yang date: 2016-12-03 --- Python学习记录day6 @(学习)[pyt ...
- Python学习记录day5
title: Python学习记录day5 tags: python author: Chinge Yang date: 2016-11-26 --- 1.多层装饰器 多层装饰器的原理是,装饰器装饰函 ...
- Python学习记录day8
目录 Python学习记录day8 1. 静态方法 2. 类方法 3. 属性方法 4. 类的特殊成员方法 4.1 __doc__表示类的描述信息 4.2 __module__ 和 __class__ ...
- Python学习记录day7
目录 Python学习记录day7 1. 面向过程 VS 面向对象 编程范式 2. 面向对象特性 3. 类的定义.构造函数和公有属性 4. 类的析构函数 5. 类的继承 6. 经典类vs新式类 7. ...
- Python学习记录:括号配对检测问题
Python学习记录:括号配对检测问题 一.问题描述 在练习Python程序题的时候,我遇到了括号配对检测问题. 问题描述:提示用户输入一行字符串,其中可能包括小括号 (),请检查小括号是否配对正确, ...
- 实验楼Python学习记录_挑战字符串操作
自我学习记录 Python3 挑战实验 -- 字符串操作 目标 在/home/shiyanlou/Code创建一个 名为 FindDigits.py 的Python 脚本,请读取一串字符串并且把其中所 ...
- 我的Python学习记录
Python日期时间处理:time模块.datetime模块 Python提供了两个标准日期时间处理模块:--time.datetime模块. 那么,这两个模块的功能有什么相同和共同之处呢? 一般来说 ...
- Python 学习记录
记录一些 学习python 的过程 -------------------------------------- 1. 初始学习 @2013年10月6日 今天开始学习python 了 遇到好多困难但是 ...
- python学习记录_IPython基础,Tab自动完成,内省,%run命令_
这是我第一次写博客,之前也有很多想法,想把自己所接触的,以文本的形式储存,总是没有及时行动.此次下定决心,想把自己所学,所遇到的问题做个记录共享给诸位,与此同时自己作为备忘,感谢各位访问我的博 ...
- Python学习记录----数据定义
摘要: 描述Python中数据定义格式,需要注意的东东. 一 数据声明 Python木有一般语言的具体数据类型,像char,int,string这些通通木有.这有点像javascript,但又不同,j ...
随机推荐
- 287. Find the Duplicate Number 找出数组中的重复数字
[抄题]: Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive ...
- [leetcode]282. Expression Add Operators 表达式添加运算符
Given a string that contains only digits 0-9 and a target value, return all possibilities to add bin ...
- pythone函数基础(10)MD5加密
导入hashlib模块import hashlibs='yulin123456's.encode()#把数字转换成bytes类型m=hashlib.md5(s.encode())print(m.hex ...
- windows 命令行出现中文乱码
1.打开CMD.exe命令行窗口 2.通过 chcp命令改变代码页chcp 65001 //UTF-8的代码页为65001
- 使用jmail发送短信
原文链接 https://blog.csdn.net/sdaujsj1/article/details/79248469 pom <!-- https://mvnrepository.com/a ...
- CSS深入理解之z-index
(http://www.imooc.com/learn/643) 一.z-index基础知识 1.z-index的含义 z-index属性指定了元素及其子元素的[z顺序],而[z顺序]可以决定当元 ...
- OSI网络七层协议+火了火了火
因为部门新进了一台价值百万的网络测试设备,所以有太大的必要了解有关网络相关的基础知识了. 网络七层协议OSI(open system interconnection)从上到下依次为:应用层.表示层.会 ...
- [JAVA]JAVA章4 Thread Dump如何分析
一.Thread Dump介绍 1.1什么是Thread Dump? Thread Dump是非常有用的诊断Java应用问题的工具.每一个Java虚拟机都有及时生成所有线程在某一点状态的thread- ...
- vue中的import、export、requre的区别
在es6之前js一直没有自己的模块语法,为了解决这种尴尬就有了require.js的出现.在es6发布之后js又引入了import的概念使得不清楚两者之间的区别的同学在实际使用过程中造成了自己的误解, ...
- Linux - rename 批量替换两种模式
模式一: rename sub raw * 模式二: rename 's/sub/raw/g' * sub raw 这里支持一定程序的正则匹配