Python tutorial #3 : IDLE

Run IDLE (interactive mode)

python

Four arithmetic operations cheat sheet

x + y   addition 
x - y   subtraction
x * y   multiplication 
x / y   division
x // y  division (fractions omitted)
x % y   surplus
-x      inversion
+x      As it is
x ** y  power 

1 + 2

2 / 4

hello IDLE

print('hellow IDLE')

Testing code across multiple lines

apple = 'fruit'

print(apple)

fruit

Keywords can be overridden as many times as you like in the python program specification. This part increases the probability of human error during large-scale development.

apple = 'red'

print(apple)

red

Python reserved words

and         A logical operator
as          To create an alias
assert      For debugging
break       To break out of a loop
class       To define a class
continue    To continue to the next iteration of a loop
def         To define a function
del         To delete an object
elif        Used in conditional statements, same as else if
else        Used in conditional statements
except      Used with exceptions, what to do when an exception occurs
False       Boolean value, result of comparison operations
finally     Used with exceptions, a block of code that will be executed no matter if there is an exception or not
for         To create a for loop
from        To import specific parts of a module
global      To declare a global variable
if          To make a conditional statement
import      To import a module
in          To check if a value is present in a list, tuple, etc.
is          To test if two variables are equal
lambda      To create an anonymous function
None        Represents a null value
nonlocal    To declare a non-local variable
not         A logical operator
or          A logical operator
pass        A null statement, a statement that will do nothing
raise       To raise an exception
return      To exit a function and return a value
True        Boolean value, result of comparison operations
try         To make a try...except statement
while       To create a while loop
with        Used to simplify exception handling
yield       To end a function, returns a generator

These keywords cannot be used because they are reserved by python in advance.

Testing code with indentation

Be sure to enter the code line by line. Please enter the code including the indent. 4 spaces are the default indent.

age = '18'

if age < 20:

    print('child')

else:

    print('adult')

child

IDLE termination method

exit()

thank you

Thank you for watching until the end. I'm glad if you can use it as a reference.

Thank you for Helping

Give money to us for Amazon gift

We will continue to update useful information. I am delighted to jump to your help. Thank you very much.