5/22/2020

Python - Preparing for a Python Interview: 10 Things You Should Know

** Preparing for a Python Interview: 10 Things You Should Know


==========================================

#1. Know how to write code on a whiteboard or paper.

#2. Know basic PYTHON control flow.

#3. Be able to discuss how you've used PYTHON.

#4. Know how to solve common interview problems.

#5. Know basic PYTHON data types and when to use them.

#6. Know how to use list comprehensions.

#7. Know how to use generators.

#8. Know the basics of OOP.

#9. Have PYTHON related questions ready to ask your interviewer.

#10. Know the basics of other technologies.

==========================================

==========================================

for i in range(1, 11):
print(i)

---------------------------------

1
2
3
4
5
6
7
8
9
10

---------------------------------

==========================================

i = 1

while i <= 10:
print(i)
i += 1

---------------------------------

1
2
3
4
5
6
7
8
9
10

---------------------------------

==========================================

a = 10
b = 20

if a < b:
print("{} is less than {}".format(a,b))

elif a == 20:
print("{} is equal to {}".format(a,b))

else:
print("{} is greater than {}".format(a,b))

---------------------------------

10 is less than 20

---------------------------------

==========================================

import os, glob

os.chdir("C:\\Users\\purunet\\Desktop\\LinuxerHaN blog")
for file in glob.glob("*.jpg"):
print(file)

---------------------------------

0.jpg
02.jpg
0b9414af9a817942fbf78c5f0d321b0d.jpg
1.jpg
1d080fc32a69dc4e278cbd8da186a043.jpg
2.jpg
2b553978cb8eadf4cf0813e67335bf97_11244249426.jpg
2bb176b1cf90c3dc3565bd48bc7e9ac4.jpg
3.jpg
4.jpg
4a23935e_2i.jpg
5.jpg
5ca203419e9574500442.jpg
6.jpg
6c1ee4b2992f99282927d6e2638eb490.jpg
7.jpg
8.jpg
8ab64f3ab4b6831f1843bd993b73d627.jpg

---------------------------------

==========================================

# fizz Buzz

for num in range(1, 101):
if num % 5 == 0 and num % 3 == 0:
print("FizzBuzz")
elif num %3 == 0:
print("Fizz")
elif num %5 == 0:
print("Buzz")
else:
print(num)

---------------------------------

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz

---------------------------------

==========================================

python 3 에서는 range() 가 xrange() 를 대신함.

==========================================

==========================================

# Fibonacci Sequence

a, b = 0, 1

for i in range(0, 10):
print(a)
a, b = b, a + b

---------------------------------

0
1
1
2
3
5
8
13
21
34

---------------------------------

==========================================

# Lists

my_list = [10, 20, 30, 40, 50]

for i in my_list:
print(i)

---------------------------------

10
20
30
40
50

---------------------------------

==========================================

# Set

my_set = {10, 20, 30, 40, 50, 10, 20, 30, 40, 50}

for i in my_set:
print(i)

---------------------------------

40
10
50
20
30

---------------------------------

==========================================

# Tuples

my_tup = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

for i in my_tup:
print(i)

---------------------------------

1
2
3
4
5
6
7
8
9
10

---------------------------------

==========================================

# Dict

my_dict = {'name': 'Bronx', 'age': '2', 'occupation': "LinuxerHAN's Cat"}

for key, val in my_dict.items():
print("My {} is {}".format(key, val))

---------------------------------

My name is Bronx
My age is 2
My occupation is LinuxerHAN's Cat

---------------------------------

==========================================

my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# Give me each number in a list squared

squares = [num * num for num in my_list]

print(squares)

---------------------------------

[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

---------------------------------

==========================================

# Fibonacci Generator

def fib(num):
a,b = 0,1
for i in range(0, num):
yield "{}: {}".format(i+1, a)
a, b = b, a+b

for item in fib(10):
print(item)


---------------------------------

1: 0
2: 1
3: 1
4: 2
5: 3
6: 5
7: 8
8: 13
9: 21
10: 34

---------------------------------

==========================================

class Person(object):
def __init__(self, name):
self.name = name

def reveal_identity(self):
print("My name is {}".format(self.name))


class SuperHero(Person):
def __init__(self, name, hero_name):
super(SuperHero, self).__init__(name)
self.hero_name = hero_name

def reveal_identity(self):
super(SuperHero, self).reveal_identity()
print("...And I am {}".format(self.hero_name))


LinuxerHAN = Person('LinuxerHAN')
LinuxerHAN.reveal_identity()

---------------------------------

My name is LinuxerHAN

---------------------------------

==========================================


class Person(object):
def __init__(self, name):
self.name = name

def reveal_identity(self):
print("My name is {}".format(self.name))


class SuperHero(Person):
def __init__(self, name, hero_name):
super(SuperHero, self).__init__(name)
self.hero_name = hero_name

def reveal_identity(self):
super(SuperHero, self).reveal_identity()
print("...And I am {}".format(self.hero_name))

SeokDu = SuperHero('SeokDu', 'Deadpool')
SeokDu.reveal_identity()

---------------------------------

My name is SeokDu
...And I am Deadpool

---------------------------------