python 编程中遇到的基本问题
来源:互联网 发布:怼的网络意思 编辑:程序博客网 时间:2024/05/18 01:24
1. 怎样查找函数的定义?
help(str.startswith)
Help on method_descriptor:
startswith(...)
S.startswith(prefix[, start[, end]]) -> bool
Return True if S starts with the specified prefix, False otherwise.
With optional start, test S beginning at that position.
With optional end, stop comparing S at that position.
prefix can also be a tuple of strings to try.
1.1 使用的str 不是 string
1.2 使用import xxx 再后使用
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'requests' is not defined
>>> import requests
>>> help(requests)
2. 怎样判断字符串,list 是否为空 和None
>>> s = ''
>>> len(s)
0
>>> lst = []
>>> len(lst)
0
>>> lst is None
False
>>> lst11 is None
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'lst11' is not defined
>>> type(None)
<type 'NoneType'>
字符串空,列表空等不能用None来判断,就是谁他们都不是None
Help on NoneType object:
class NoneType(object)
| Methods defined here:
|
| __hash__(...)
| x.__hash__() <==> hash(x)
|
| __repr__(...)
| x.__repr__() <==> repr(x)
None 的用途是什么,暂且理解为: void数据类型,可接收任何赋值
3. 关于 +
同种类型才能相加
如字符串: str1 = '1qaz' + '1qaxff'
列表: lst1 = [1,2] + [(1,3),(1,3)] + ['1qq']
但是,添加元素不能用: +, 两者不是同种类型
ls1 += '1qq', 意图时ls1 添加元素, 但实际结果如下:自动把字符串转换为list
>>> ls1 = ['1q']
>>> ls1 += '1qq'
>>> print ls1
['1q', '1', 'q', 'q']
4. python 函数的调用
参数不存在数据类型和变量之说,只有变量
def fun(s1, nub):不像 C
void fun(char* s1, int nub)
- python 编程中遇到的基本问题
- python 网络编程中遇到的问题
- Python 编程中遇到的几个小问题
- python中遇到的问题
- 写django中遇到的基本问题。
- Ubuntu中遇到的基本问题
- 编程中遇到的有趣的问题
- python中遇到的小问题
- python xmlrpc中遇到的问题
- Python打包过程中遇到的问题
- python MySQLdb安装中遇到的问题
- python中遇到的小问题
- python学习中遇到的问题
- Python学习中遇到的问题
- python中遇到的那些问题
- python学习中遇到的问题
- python 安装中遇到的问题
- apache python配置中遇到的问题
- C#应用WindowsApi实现查找\枚举(FindWindow、EnumChildWindows)窗体控件,并发送消息。
- EBS中可以建立ASN但不能建立ASBN
- 【Linux4.1.12源码分析】邻居子系统实现分析
- Linux下Sublime Text 2的安装
- XML、JSON及其解析
- python 编程中遇到的基本问题
- oracle 数据库应用
- activiti采购申请-批准实例
- yii自带rbac数据表分析
- 原码、反码、补码,计算机中负数的表示
- 洛谷 1242
- 多路复用之poll函数
- Leetcode 91. Decode Ways
- gdb调试——.gdbinit脚本