Python is an easy and powerful script language.
Let's start it with the "Hello world!"
print("Hello world!")
- You don't need semicolon at the end.
- If you added a semicolon, it's fine. It will not give an error for that.
- Indentation matters: instead of {}
- Common grammers like data type, operators, etc. work
- It's a script language, so the definition order matters.
You don't use () for condition.
You can use a colon instead.
if condition==true:
do(this)
else:
do(that)
It is similar to if statement.
Colon and indentation matter.
while condition==true:
keepDoing(this)
In Python, you can directly reference list items for for iteration, without defining an index variable.
for item in itemList:
process(item)
If you want to use index, change the code like this.
for i in range(count):
process(itemList[i])
Lastly, define a function like this.
You can remove the return statement if you don't need it.
def functionName(functionVariables):
result = process(functionVariables)
return result