python-2
来源:互联网 发布:好看的网络自制剧穿越 编辑:程序博客网 时间:2024/06/15 23:52
s = "ian"ret = "ia" in sprint(ret)li = ["penny","jack","ian"]ret = "ian" in liprint(ret)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
数字:int
n1 = 123
n2 = 456
print (n1+n2)
传参>>self 不需传参>>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
字符串:str
class str(object): """ str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'. """ def capitalize(self): # real signature unknown; restored from __doc__ """ S.capitalize() -> str Return a capitalized version of S, i.e. make the first character have upper case and the rest lower case. """ return ""
a1 = "ian"ret = a1.capitalize()print(ret)
def center(self, width, fillchar=None): # real signature unknown; restored from __doc__ """ S.center(width[, fillchar]) -> str Return S centered in a string of length width. Padding is done using the specified fill character (default is a space) """ return "" def count(self, sub, start=None, end=None): # real signature unknown; restored from __doc__ """ S.count(sub[, start[, end]]) -> int Return the number of non-overlapping occurrences of substring sub in string S[start:end]. Optional arguments start and end are interpreted as in slice notation. """ return 0 def encode(self, encoding='utf-8', errors='strict'): # real signature unknown; restored from __doc__ """ S.encode(encoding='utf-8', errors='strict') -> bytes Encode S using the codec registered for encoding. Default encoding is 'utf-8'. errors may be given to set a different error handling scheme. Default is 'strict' meaning that encoding errors raise a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and 'xmlcharrefreplace' as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors. """ return b"" def endswith(self, suffix, start=None, end=None): # real signature unknown; restored from __doc__ """ S.endswith(suffix[, start[, end]]) -> bool Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. suffix can also be a tuple of strings to try. """ return False
a1 = "ian"ret = a1.center(20,'*')print(ret)
a1 = "ian a a a "ret = a1.count("a")print(ret)
a1 = "ian a a a "# ret = a1.count("a")ret = a1.count('a',0, 3)print(ret)
temp = "hello"print(temp.endswith('o'))
s = "hello {0}, age {1}"print(s)new1 = s.format("ian", 19)print(new1)
a = "ian9"ret = a.isalnum()print(ret)li = ["ian", "eric"]s = "_".join(li)print(s)
s = " ian "# n = s.lstrip()# n=s.rstrip()n = s.strip()print(n)
s = "ian aa ian"ret = s.partition("aa")print(ret)
s = "ian aa ian aa"ret = s.replace("aa", "bb", 1)print(ret)
s = "ian"start = 0while start < len(s): temp = s[start] print(temp) start +=1for i in s: if i == "a": break print(i)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
布尔值:bool
列表:list
class list(object): """ list() -> new empty list list(iterable) -> new list initialized from iterable's items """ def append(self, p_object): # real signature unknown; restored from __doc__ """ L.append(object) -> None -- append object to end """ pass def clear(self): # real signature unknown; restored from __doc__ """ L.clear() -> None -- remove all items from L """ pass def copy(self): # real signature unknown; restored from __doc__ """ L.copy() -> list -- a shallow copy of L """ return [] def count(self, value): # real signature unknown; restored from __doc__ """ L.count(value) -> integer -- return number of occurrences of value """ return 0 def extend(self, iterable): # real signature unknown; restored from __doc__ """ L.extend(iterable) -> None -- extend list by appending elements from the iterable """ pass def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__ """ L.index(value, [start, [stop]]) -> integer -- return first index of value. Raises ValueError if the value is not present. """ return 0 def insert(self, index, p_object): # real signature unknown; restored from __doc__ """ L.insert(index, object) -- insert object before index """ pass def pop(self, index=None): # real signature unknown; restored from __doc__ """ L.pop([index]) -> item -- remove and return item at index (default last). Raises IndexError if list is empty or index is out of range. """ pass def remove(self, value): # real signature unknown; restored from __doc__ """ L.remove(value) -> None -- remove first occurrence of value. Raises ValueError if the value is not present. """ pass def reverse(self): # real signature unknown; restored from __doc__ """ L.reverse() -- reverse *IN PLACE* """ pass def sort(self, key=None, reverse=False): # real signature unknown; restored from __doc__ """ L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE* """ pass def __add__(self, *args, **kwargs): # real signature unknown """ Return self+value. """ pass def __contains__(self, *args, **kwargs): # real signature unknown """ Return key in self. """ pass
# list# # name_list.append("shirly")# name_list.append("shirly")# name_list.append("shirly")# print(name_list.count("shirly"))# print(name_list)# # temp = [11, 22, 33, 44]# name_list.extend(temp)# print(name_list)# # print(name_list.index("penny"))# name_list.insert(1,"tom")# print(name_list)# a1 = name_list.pop()# print(name_list)# # print(a1)# # name_list.remove("shirly")# print(name_list)# name_list.reverse()# print(name_list)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
元组:tuple
print(name_tuple[len(name_tuple)-1])print(name_tuple[0:1])for i in name_tuple: print(i)print(name_tuple.index("jack"))print(name_tuple.count("jack"))
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
字典:dict
user = { "name": "ian", "age": 11, "gender": "male"}dictprint(user["name"])for i in user: print(i)print(user.keys())print(user.values())print(user.items())for i in user.keys(): print(i)for i in user.values(): print(i)for i in user.items(): print(i)getval = user.get("age")print(val)val = user.get("age111", "123")print(val)# ret = "age" in user.keys()# print(ret)print(user)test = { "1": 123, "2": 456,}user.update(test)print(user)
temp = "ian"print(temp)temp_new = temp.upper()print(temp_new)
temp = "ian"#通过type获取字符串 类型jack = type(temp)print(jack)print(type(temp))str#调用功能temp_new = temp.upper()print(temp_new)
#查看对象的类,对象的功能 type dir helptemp = "ian"b = dir(temp)print(b)temp = "ian"help(type(temp))
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
》》》不同类型功能不同》》》功能》模板》类》对象》地址》》
方法在相对的值>(类)>对象的功能在对象相关联的类中》》》不同类型功能不同》》》功能》模板》类》对象》地址》》
阅读全文
0 0
- python 2 & python 3
- Python--python基础知识(2)
- 【python】python基础知识2
- Python-(2)
- Python(2)
- python(2)
- Python - 2
- Python(2)
- Python-2
- python(2)
- Python 2
- python-2
- python(2)
- python 2 和 python 3
- Python-2 Python小程序
- Python 语言介绍--Python(2)
- Python print 语句(Python 2 与 Python 3)
- Python 初学者 入门 应该学习 python 2 还是 python 3?
- Linux安装mysql及删除
- 基于电信业务的第三方测试服务实践
- 新书《Cocos2dx 3.x 3D图形学渲染技术讲解》问世
- 利用c标签根据list数据源进行表格布局
- js获取页面元素高度、宽度
- python-2
- 初识UML(1)
- html补充笔记和CSS命名规范
- Struts2:前后台的数据交互
- static和const
- redis及php扩展配置(windows+php5)
- sqlplus调用sql脚本执行时报错SP2-0734: unknown command beginning的解决方法
- 剑指offer 之 栈的压入、弹出序列是否对应
- Android UI 之 TabLayout动态添加tab实现筛选及自动偏移(全选,单选)