Python数据分析笔记 1
print ( "hello world" )
hello world
name = "小李"
gender = "男"
age = 18
high = 185.6
print ( "姓名:%s\n" "性别:%s\n" "年龄:%d \n" "身高: %.1f" % ( name, gender, age, high) )
姓名:小李
性别:男
年龄:18
身高: 185.6
a, b, c = map ( int , input ( "请输入三个数字" ) . split( ) )
def sum ( x, y, z) :
return x+ y+ z
sum ( a, b, c)
请输入三个数字 3 4 5
12
c = '关于我在B站学习数据分析这档事儿 '
d = 'I am studying Data Analyse in Bilibili'
print ( c. strip( ) )
print ( d. replace( ' ' , '' ) )
a, b = input ( "输入连个字符串,空格分开" ) . split( )
print ( a+ b)
关于我在B站学习数据分析这档事儿
IamstudyingDataAnalyseinBilibili
输入连个字符串,空格分开 我爱 学习
我爱学习
dtype('int64')
edge = int ( input ( "please input on number of edge" ) )
L = 4 * edge
S = edge* edge
print ( "edge = %d\n" "L = %d\n" "S = %d\n" % ( edge, L, S) )
please input on number of edge 4
edge = 4
L = 16
S = 16
a = 6.89
b = 8.9
def change ( x, y) :
z = x
x = y
y = z
print ( "a = %.1f\n" "b= %.2f" % ( x, y) )
change( a, b)
a = 8.9
b= 6.89
string = input ( "任意输入一段字符串" )
print ( string[ : : - 1 ] )
for i in range ( len ( string) - 1 , - 1 , - 1 ) :
print ( string[ i] , end = '' )
print ( "\n" )
str = list ( string)
str . reverse( )
print ( '' . join( str ) )
def des_output ( s) :
if ( len ( s) > 0 ) :
print ( s[ - 1 ] , end = '' )
des_output( s[ 0 : - 1 ] )
des_output( string)
任意输入一段字符串 我是中国人
人国中是我
人国中是我
人国中是我
人国中是我
S = input ( '请输入字符串:' )
print ( S[ : : - 1 ] )
print ( S[ 0 : - 1 ] )
print ( S[ 0 : 1 ] )
print ( S[ - 1 ] )
请输入字符串: 12345
54321
1234
1
5
int_ = 1
print ( '类型为:%s' % type ( int_) )
bool_ = True
print ( '类型为:%s' % type ( bool_) )
类型为:<class 'int'>
类型为:<class 'bool'>
"""
互相转换
int():将一个数值或字符串转换成整数,可以指定进制。
float():将一个字符串转换成浮点数。
str():将指定的对象转换成字符串形式,可以指定编码。
chr():将整数转换成该编码对应的字符串(一个字符)。
ord():将字符串(一个字符)转换成对应的编码(整数)。
也就是,我把我套到你身上,你就会变成我的类型。
"""
'\n互相转换\nint():将一个数值或字符串转换成整数,可以指定进制。\nfloat():将一个字符串转换成浮点数。\nstr():将指定的对象转换成字符串形式,可以指定编码。\nchr():将整数转换成该编码对应的字符串(一个字符)。\nord():将字符串(一个字符)转换成对应的编码(整数)。\n也就是,我把我套到你身上,你就会变成我的类型。\n'
L1 = [ '凌波丽' , '碇真嗣' , '明日香' ]
list ( enumerate ( L1) )
[(0, '凌波丽'), (1, '碇真嗣'), (2, '明日香')]
count = 1
for i in L1:
print ( '现在正在遍历第{}个值,它是:{}\n' . format ( count, i) )
count = count + 1
现在正在遍历第1个值,它是:凌波丽
现在正在遍历第2个值,它是:碇真嗣
现在正在遍历第3个值,它是:明日香
driver = [ '碇真嗣' , '明日香' , '铃原东治' , '真希波' , '渚薰' ]
charactor = [ ]
count = 0
for i in driver:
count = count + 1
charactor. append( i)
print ( '\n执行第:{}次,charactor = {}' . format ( count, charactor) )
charactor
执行第:1次,charactor = ['碇真嗣']
执行第:2次,charactor = ['碇真嗣', '明日香']
执行第:3次,charactor = ['碇真嗣', '明日香', '铃原东治']
执行第:4次,charactor = ['碇真嗣', '明日香', '铃原东治', '真希波']
执行第:5次,charactor = ['碇真嗣', '明日香', '铃原东治', '真希波', '渚薰']
['碇真嗣', '明日香', '铃原东治', '真希波', '渚薰']
T1 = ( '凌波丽' , '碇真嗣' , '明日香' )
T1
('凌波丽', '碇真嗣', '明日香')
a= 1
b= 2
print ( a, b)
1 2
set1 = { 1 , 2 , 3 , 3 , 3 , 2 }
set2 = { 1 , 1 , 4 , 4 , 3 , 2 }
print ( set1, set2)
print ( 'Length1 = {},Length2 = {}' . format ( len ( set1) , len ( set2) ) )
{1, 2, 3} {1, 2, 3, 4}
Length1 = 3,Length2 = 4
print ( set1 & set2)
print ( set1 | set2)
print ( set1 - set2)
print ( set1 ^ set2)
{1, 2, 3}
{1, 2, 3, 4}
set()
{4}
EVA1 = { '凌波丽' : 'EVA零号机' , '碇真嗣' : 'EVA初号机' , '明日香' : 'EVA二号机' }
EVA2 = dict ( zip ( [ '凌波丽' , '碇真嗣' , '明日香' ] , [ 'EVA零号机' , 'EVA初号机' , [ 'EVA二号机' , 'EVA三号机' ] ] ) )
print ( EVA1. keys( ) )
print ( EVA2. values( ) )
dict_keys(['凌波丽', '碇真嗣', '明日香'])
dict_values(['EVA零号机', 'EVA初号机', ['EVA二号机', 'EVA三号机']])