(牛客网)《北京理工大学大学计算机历年考研复试上机题》使用Python总结

一.输入与输出

  1.m=int(input())                               #输入字符串转化为整数

  2.mylist=list(map(int,input().split()))#输入一行数据用空格分隔,每个数据用int转换成整数,返回list

  3.print("%04d ::%.2f" %(a,b) )        #格式化输出

  4.print默认换行,要想不换行须加 end=""

二.循环

  1.for i in range(5)                 #默认从0开始,不含5

  2.for it in mylist                    #循环取mylist中的元素

  3.for i in range(0,len(mylist))#根据mylist[i]

三.字符串处理

  1." ".join(mylist) #将mylist(str)中的元素用空格分隔形成字符串

  2.str[::-1]#反转字符串

四.类

  1.成员函数想要使用成员变量要带self作为第一个形参,并使用self.成员变量

  2.重载运算符须参考内置函数

五.技巧

  1.当根据多个字符分隔字符串时可以先将分隔字符替换成统一字符在进行分隔:

    b=a.lower().replace(',',' ').replace('.',' ').split()

  2.

猜你喜欢

转载自www.cnblogs.com/hsly-bhj/p/10704916.html
今日推荐