Correct syntax:
if 5 > 2:
print("Five is greater than two!")
Wrong syntax:
if 5 > 2:
print("Five is greater than two!")
Python is a popular programming language. It was created by Guido
van Rossum, and released in 1991.
It is used for:
web development (server-side),
software development,
mathematics,
system scripting.
Python is powerful... and fast; plays well with others; runs everywhere; is friendly & easy to learn; is Open.
Not any as such, but if you know basics of programming languages like C, C++ or Java that might come in handy.
Correct syntax:
if 5 > 2:
print("Five is greater than two!")
Wrong syntax:
if 5 > 2:
print("Five is greater than two!")
print("Hello World")
a = "Hello"
x = 1 # int
y = 2.8 # float
z = 1j # complex
thislist = ["apple", "banana", "cherry"] # list
thistuple = ("apple", "banana", "cherry") # tuple
thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964
}
thisset = {"apple", "banana", "cherry"}
To know datatype of variable x:
print(type(x))
And More
For example: Print i as long as i is less than 6-
i = 1
while i < 6:
print(i)
i += 1
For example: Print each fruit in a fruit list-
fruits = ["apple", "banana", "cherry"]
for x in fruits: < 6:
print(x)
For example:
def my_function():
print("Hello from a function")
my_function()
For example: Create a class named MyClass, with a property named
x:
class MyClass:
x = 5
Now we can use the class named MyClass to create objects:
p1 = MyClass()
print(p1.x)
The simplest way to use urllib.request is as follows:
import urllib.request with
urllib.request.urlopen('http://python.org/') as response: html =
response.read()