This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_formatted_name(first_name,last_name): | |
"""return full name""" | |
full_name=first_name+' '+last_name | |
return full_name.title() | |
def print_full_name(): | |
while True: | |
print("\nPlease tell me your name:") | |
print("(enter 'q' at any time to quit)") | |
f_name=input("First name:") | |
if f_name=='q': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def build_person(first_name,last_name,age=''): | |
"""return a dictionary, its about a person's information""" | |
person={'first':first_name,'last':last_name} | |
if age: | |
person['age']=age | |
return person | |
musician=build_person('jimi','hendrix',age=27) | |
print(musician) | |
""" | |
OUTPUT: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def describe_city(city,country="Taiwan"): | |
if city is "Tainan" or city is "Taipei": | |
print("\n "+city+" is in "+country) | |
else: | |
print("\n "+city+" is not in "+country) | |
describe_city(city="Tainan") | |
describe_city(city="Taipei") | |
describe_city(city="New York") | |
""" | |
OUTPUT: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_shirt(size,text="I love Python"): | |
print("\n The shirt size is "+size+".") | |
print("\n The shirt text is "+text+".") | |
make_shirt(size="big") | |
make_shirt(size="medium",text="Python is good") | |
""" | |
OUTPUT: | |
The shirt size is big. | |
The shirt text is I love Python. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def describe_pet(pet_name,animal_type='dog'): | |
"""show pet information""" | |
text="\n I have a "+animal_type+"." | |
text+="\n My "+animal_type+"'s name is "+pet_name.title()+"." | |
print(text) | |
return text | |
describe_pet(pet_name="harry") | |
""" | |
OUTPUT: | |
I have a dog. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
cv2.namedWindow("preview") | |
vc = cv2.VideoCapture(0) | |
if vc.isOpened(): # try to get the first frame | |
rval, frame = vc.read() | |
else: | |
rval = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/questions/4440516/in-python-is-there-an-elegant-way-to-print-a-list-in-a-custom-format-without-ex | |
lst = [[1, 2],[ 3,4]] | |
>>> print('\n'.join('{}: {}'.format(*k) for k in enumerate(lst))) | |
0: [1, 2] | |
1: [ 3,4] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://stackoverflow.com/questions/12934190/is-there-a-short-contains-function-for-lists | |
if myItem in list: | |
# do something | |
#Also, inverse operator: | |
if myItem not in list: | |
# do something |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python 3 | |
# https://stackabuse.com/getting-user-input-in-python/ | |
# https://www.geeksforgeeks.org/python-output-formatting/ | |
txt = input("Type something to test this out: ") | |
print("Is this what you just said? %s"%( txt)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/questions/33650974/opencv-python-read-specific-frame-using-videocapture | |
import numpy as np | |
import cv2 | |
cap = cv2.VideoCapture(video_name) #video_name is the video being called | |
cap.set(1,frame_no); # Where frame_no is the frame you want | |
ret, frame = cap.read() # Read the frame | |
cv2.imshow('window_name', frame) # show frame on window | |
#If you want to hold the window, until you press exit: | |
while True: |
NewerOlder