Python面试题30道(下)
30 Essential Python Interview Questions You Should Know.
###Q-16: How Does The Ternary Operator Work In Python?
1 | x, y = 35, 75 |
###Q-17: What Does The
self就是self呀
###Q-18: What Are Different Methods To Copy An Object In Python?
基础的l2=l1[:]
copy.copy()
- 外层copy,内层会随着原对象改变,抄了作业还要跟着改
copy.deepcopy() - 内层copy,抄完作业就不改了
###Q-19: What Is The Purpose Of Doc Strings In Python?
给你一个BB机会
1 | class A(object): |
###Q-20: Which Python Function Will You Use To Convert A Number To A String?
str()
###Q-21: How Do You Debug A Program In Python? Is It Possible To Step Through Python Code?
1 | import pdb |
###Q-22: List Down Some Of The PDB Commands For Debugging Python Programs?
- Add breakpoint – b
- Resume execution – c
- Step by step debugging – s
- Move to next line – n
- List source code – l
- Print an expression – p
###Q-23: What Is The Command To Debug A Python Program?
1 | python -m pdb debug_file.py |
###Q-24: How Do You Monitor The Code Flow Of A Program In Python?
1 | import sys |
###Q-25: Why And When Do You Use Generators In Python?
###Q-26: What Does The
协程
###Q-27: How To Convert A List Into Other Data Types?
to String
1 | weekdays = ['sun','mon','tue','wed','thu','fri','sat'] |
to Tuple
1 | weekdays = ['sun','mon','tue','wed','thu','fri','sat'] |
to Set
1 | weekdays = ['sun','mon','tue','wed','thu','fri','sat','sun','tue'] |
to Dictionary
1 | weekdays = ['sun','mon','tue','wed','thu','fri'] |
###Q-28: How Do You Count The Occurrences Of Each Item Present In The List Without Explicitly Mentioning Them?
1 | weekdays = ['sun','mon','tue','wed','thu','fri','sun','mon','mon'] |
###Q-29: What Is NumPy And How Is It Better Than A List In Python?
Numpy底层结构不一样,c写的,而且优化的很好
###Q-30: What Are Different Ways To Create An Empty NumPy Array In Python?
看Numpy的文档吧 0.0