23
loading...
This website collects cookies to deliver better user experience
(cmd.exe):
C:\Users\Your Name>python --version
python --version
>>> print("Hello, World!")
Hello, World!
if 5 > 2:
print("Five is greater than two!")
#This is a comment
print("Hello, World!")
"""
This is a comment
written in
more than just one line
"""
print("Hello, World!")
x = 5
y = "John"
print(x)
print(y)
x = 5
y = "John"
print(type(x))
print(type(y))
This will create two variables:
a = 4
A = "Sally"
#A will not overwrite a
Text Type: str
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
a = 33
b = 200
if b > a:
print("b is greater than a")
a = 33
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
x = 5
print(type(x))
Print i as long as i is less than 6:
i = 1
while i < 6:
print(i)
i += 1
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
for x in "banana":
print(x)
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
if x == "banana":
break
fruits = ["apple", "banana", "cherry"]
for x in fruits:
if x == "banana":
continue
print(x)
for x in [0, 1, 2]:
pass
for x in range(6):
print(x)
else:
print("Finally finished!")
def my_function():
print("Hello from a function")
def my_function():
print("Hello from a function")
my_function()
def my_function(fname):
print(fname + " Refsnes")
my_function("Emil")
my_function("Tobias")
my_function("Linus")
def my_function(fname, lname):
print(fname + " " + lname)
my_function("Emil", "Refsnes")
def my_function(country = "Norway"):
print("I am from " + country)
my_function("Sweden")
my_function("India")
my_function()
my_function("Brazil")
lambda arguments : expression
x = lambda a : a + 10
print(x(5))
def myfunc(n):
return lambda a : a * n
def myfunc(n):
return lambda a : a * n
mydoubler = myfunc(2)
print(mydoubler(11))
car1 = "Ford"
car2 = "Volvo"
car3 = "BMW"
x = cars[0]
cars.append("Honda")
cars.pop(1)