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 ...
随机推荐
- Ubuntu安装软件提示boot空间不足
用sudo apt-get install gitlab-ci-multi-runner安装应用都会出现“gzip: stdout: No space left on device”的问题. boot ...
- 十五、Facade 窗口设计模式
需求:让复杂的事务看起来简单 原理: 代码清单: DataBase: public class DataBase { private DataBase(){} public static Proper ...
- java正则积累
1. [.]点:再分割的时候不可以直接使用点,需要加上 \\ 转义才可以得到想要的结果,否则输出的时候会报异常 数据下标越界 String[] split = "output.txt&quo ...
- 命名空间 extern的用法 static全局变量
std是标准库中的命名空间: 关于extern的用法可以参考文献http://blog.163.com/sunjinxia%40126/blog/static/94984879201312145021 ...
- [leetcode]150. Evaluate Reverse Polish Notation逆波兰表示法
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
- node.js中fs文件系统模块的使用
node.js中为我们提供了fs文件系统模块,实现对文件或目录的创建,修改和删除等操作. fs模块中,所有的方法分为同步和异步两种实现. 有 sync 后缀的方法为同步方法,没有 sync 后缀的方法 ...
- Spring MVC 中的输入验证 Vlidator
在 Spring MVC 中有两种方式可以验证输入:1. Spring 自带的验证框架:2. 利用 JSR 303 实现,即 Java Specification Requests Converter ...
- 【APP测试(Android)】--用户体验
- 别人的Linux私房菜(11)认识与学习BASH
Linux下使用BASH Bourne Again Shell 另外一种由用于Unix的伯克利大学的Bill Joy设计的C Shell 系统中合法的shell会写入到/etc/sh ...
- docker 技术
利用docker打包一个sshd的服务 准备环境 安装docker 修改主机名与hosts解析 echo '10.0.0.11 docker01' 参考文档:https://m ...