Skip to content

Commit fa33236

Browse files
committed
explain functions and keywords
1 parent dcc959c commit fa33236

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

if.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@ It's raining!
5353
>>>
5454
```
5555

56+
But why is that `if its_raining` instead of `if(its_raining)`?
57+
58+
Earlier we learned that `if` is a **keyword**.
59+
60+
```py
61+
>>> if = 123
62+
File "<stdin>", line 1
63+
if = 123
64+
^
65+
SyntaxError: invalid syntax
66+
>>>
67+
```
68+
69+
Functions like `print` need `()` after their name to work. But `if` is
70+
a keyword, not a function, so it doesn't need `()`. Python has separate
71+
functions and keywords because it's possible to create custom functions,
72+
but it's not possible to create custom keywords. That's why keywords are
73+
usually used for "magic" things that would be difficult to do with just
74+
functions.
75+
76+
## Storing code in files
77+
5678
At this point it's easier to put your code into a file and use it
5779
there. If you use IDLE, go to File at top left and select New File, or
5880
just press Ctrl+N.

0 commit comments

Comments
 (0)