This file contains hidden or 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
number = 9.5 | |
# or you can do this | |
number = float(9) | |
# the above line converts nine from int to float and then save it in the number variable | |
# or even this can be used | |
number = 9.0 | |
# in the above line we have added a decimal point so it is converted into a float |
This file contains hidden or 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
name = "Chuck Norris" | |
# or use this | |
name = 'Chuck Norris' | |
# so the difference is of the type of qoutes | |
# have fun |
This file contains hidden or 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
i_am_programmer = True | |
# The above example creates a variable and assigns it as True | |
i_am_not_a_programmer = False | |
# The above example creates a variable and assigns it as False | |
# or you can do this | |
i_am_programmer = bool(1) # 1 or any number except 0 | |
i_am_not_a_programmer = bool(0) # 0 is the only number which can assign False |
This file contains hidden or 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
# create a string variable | |
name = "Padmashree" | |
# print string variable | |
print(name) | |
# create a float variable | |
float_number = 4.5 | |
# print float variable |
This file contains hidden or 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
name = input("What is your name") | |
# take input from the user and save it in the name variable as string | |
# print the name | |
print(name) |
This file contains hidden or 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
# declare a string variable | |
name = "Padmashree" | |
# print variable name in upper case | |
print(name.upper()) | |
# print the vriable in lower case | |
print(name.lower()) | |
# directly print a word in lower case |
This file contains hidden or 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
# create a string variable | |
name = "Padmashree" | |
# print the first charachter of the word | |
print(name[0]) | |
# prints P | |
# print the last charachter of the word | |
print(name[-1]) | |
# prints e |
This file contains hidden or 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
# create a string variable | |
name = "Padmashree" | |
# print every word after the fifth charachter | |
print(name[5:]) | |
# prints shree | |
# print every word before the fifth charachter | |
print(name[:5]) | |
# prints Padma |
This file contains hidden or 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 | |
# for in-built camera | |
cam = cv2.VideoCapture(0) | |
# for external camera | |
cam = cv2.VideoCapture(0, cv2.CAP_DSHOW) |
This file contains hidden or 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 | |
# I used this line because I have external camera. | |
# You do not need to use cv2.CAP_DSHOW if you do not use external camera | |
cam = cv2.VideoCapture(0, cv2.CAP_DSHOW) | |
while True: | |
ret, frame = cam.read() | |
cv2.imshow("My Webcam", frame) | |
key = cv2.waitKey(25) | |
if key == ord('q'): | |
break |