一、python基础

python

 

About the author:

name:zhanghan

email:rwzhanghan@163.com

motto:~

notes:This article and the link content belong to the author. If there is a note statement of non author link.


 

 

#coding=utf-8
# -*- coding:utf-8 -*-
'''中文支持需首行添加编码'''
type(变量的名字) # 查看变量的类型
标识符:由字母、下划线、数字组成,且数字不能开头,不能使用关键字(大驼峰、小驼峰、下划线)
print('输出')  rint('xxx%s' % (变量名))  print(f'xxx{变量名},xxx{变量名}')
(%c——字符)(%s——字符串)(%d——整数)(%f——浮点数)(\n——换行)(\t——对齐)
input('请输入:输出')
运算符:=赋值 (1)**指数;(2)*乘、/除、%取余、//取整;(3)+加、-减;  括号处理运算优先级
== 比较为真、!= 比较为反、> 大于右边真、< 小于右边真、>= 大于或等于真、<= 小于或等于真、
and和、or或、not非
数据转换:eval()返回对象、int()整数、float()浮点数、str()字符串、tuple()元组、list()列表、
判断: (1)if:elif:else:/  (2)while:if:elif:else:/  (3)for:if:elif:else:
break退出本次循环、continue结束本次继续下次

'''布尔类型:True/False'''

0、numbers(数字)

int整型、long长整型8/16进制、float浮点型、complex复数

1、string (字符串)

# 变量在双引号或单引号内的数据是字符串类型
下标切片:name = 'zxcvbnm' print(name[起始:结束:步长])
find:mystr.find(str, start=0, end=len(mystr))是否在内在返回开始索引值,反之返回-1
index:mystr.index(str, start=0, end=len(mystr)) 是否在内在返回开始索引值,反之报错
count:mystr.count(str, start=0, end=len(mystr))返回出现次数
replace:mystr.relace(str1, str2, mystr.count(str1)) 1换成2,最多count次
join:mystr.join(str)在每个元素后插入str
split:mystr.split(str='',2)分割
partition:mystr.patition(str)分成三部分str前、str、str后
splitlines:mystr.splitlines()按行分割返回各行作为元素的列表

# 充填空白字符
ljust:mystr.ljust(width)左对齐,空格填充至长度width的新字符串
rjust:mystr.rjust(width)右对齐,空格填充至长度width的新字符串
center:mystr.center(width)居中,空格填充至长度width的新字符串

# 删除空白字符
lstrip:mystr.lstrip()删除mystr左边的空白字符
rstrip:mystr.rstrip()删除mystr末尾的空白字符
strip:mystr.strip()删除mystr两端的空白字符

# 判断
isalpha:mystr.isalpha()所以都是字母是True否False
isdigit:mystr.isdigit()所以都是数字是True否False
isalnum:mystr.isalnum()所以都是字符串或数字是True否False
isspace:mystr.isspace()只包含空格是True否False
startswith:mystr.startswith(hello)检查字符串以xxx开头是True否False
endswith:mystr.endswith(obj)检查字符串以xxx结束是True否False

# 大小写
capitalize:mystr.capitalize()把字符串的第一个字母大写
title:mystr.title()把字符串的每个字母大写
lower:mystr.lower()转换mystr中所以大写变小写
upper:mystr.upper()转换mystr中所以小写变大写

 

2、list(列表)

  pass

3、tuple(元组)

  pass

4、dictionary(字典)

  pass


 

  未完待续  ......

 

posted @ 2020-05-16 16:52  涵z  阅读(235)  评论(0编辑  收藏  举报