Python For Kids For Dummies book cover

Python For Kids For Dummies

By: Brendan Scott Published: 09-08-2015

The kid-friendly way to learning coding with Python

Calling all wanna-be coders! Experts point to Python as one of the best languages to start with when you're learning coding, and Python For Kids For Dummies makes it easier than ever. Packed with approachable, bite-sized projects that won't make you lose your cool, this fun and friendly guide teaches the basics of coding with Python in a language you can understand. In no time, you'll be installing Python tools, creating guessing games, building a geek speak translator, making a trivia game, constructing a Minecraft chat client, and so much more.

Whether you don't have the opportunity to take coding classes at school or in camp—or just simply prefer to learn on your own—Python For Kids For Dummies makes getting acquainted with this popular coding language fast and easy. It walks you step-by-step through basic coding projects and provides lots of hands-on tasks that give you a sweet sense of accomplishment when you complete them. What's not to love about that?

  • Navigate the basics of coding with the Python language
  • Create your own applications and games
  • Find help from other Python users
  • Expand your technology skills with Python

If you're a pre-to-early-teen looking to add coding skills to your creativity toolbox, Python For Kids For Dummies is your sure-fire weapon for getting up and running with one of the hottest programming languages around.

Articles From Python For Kids For Dummies

page 1
page 2
19 results
19 results
Python For Kids For Dummies Cheat Sheet

Cheat Sheet / Updated 02-24-2022

Python coding helps you with things you do every day, like math homework. Python programming can also help with things like making web pages: Thank goodness for widgets and keywords!

View Cheat Sheet
How to Install Python on Your Computer

Article / Updated 01-25-2022

Whether you use a Mac, Windows, or Linux OS (operating system), you can find and install Python on your computer. The following sections give you instructions for each OS. How to install Python on Mac OSX To find and start Python on Mac OSX computers, follow these steps: Press Cmd+spacebar to open Spotlight. Type the word terminal. Or, from the Finder, select Finder→Go→Utilities→Terminal. The Terminal window opens. In the terminal, type python. The Python interpreter that's built in to Mac OSX opens. How to install Python on Windows Unfortunately, Python doesn't come on Windows. If you're running Windows, then you need to download and install Python by following the instructions here. Installing Python on Windows isn't difficult. If you can download a file from a website, you have the skills to install Python. Fortunately, the Python Foundation (the peeps who guide the development of Python) makes installable files available from its website. Firefox and Internet Explorer responded differently to the Python download website, so the instructions are based on which of these browsers you use. If you use a whole other browser altogether, try the Internet Explorer instructions. Installing with Firefox To install Python on a Windows machine with Firefox, follow these steps: Visit www.python.org/downloads. Click the button that says Download Python 2.7.9. Or, if it's there, click a more recent version number that starts with 2.7. Clicking this button automatically downloads and saves an msi file for you. If not, try the instructions for Internet Explorer. See Figure 1. Figure 1: Download Python with Firefox. When the download's complete, click the icon for Firefox's download tool. Click the file called python-2.7.9.msi (or the more recent version, if you downloaded one). Python 2.7.9 installs on your computer. Installing with Internet Explorer To install Python on a Windows machine with Internet Explorer, follow these steps: Visit www.python.org/downloads. From the menu bar, select Downloads→Windows. You can see the menu options in Figure 2. Figure 2: Download Python with Internet Explorer. Scroll down to the heading Python 2.7.9-2014-12-10. Or scroll to a more recent version, which starts with Python 2.7, if one is available. Under this heading, click the link titled Download Windows x86 MSI Installer. See Figure 3. This is a link for a 32-bit installation, which makes things work better with third-party libraries. Use the 32-bit installer even if you have a 64-bit machine and even if you have no idea what this paragraph is talking about. Figure 3: Python x86 MSI Installer. If you're asked to choose whether to run or save the file, choose Run. This downloads python2.7.9.msi and starts running the installer. If you get a security warning when the installer begins (or at random times during the installation), choose Run. Accept the default installation options that the installer provides. How to install Python for Linux If you're running Linux, confirm that you have version 2.7.9 of Python installed, rather than version 3. This shouldn't be a problem because Python 2.7 is installed by default in recent versions of OpenSuSE, Ubuntu, and Red Hat Fedora. In the nutty odd case when someone has Python 3 but not Python 2.7, read your distribution's documentation for how to use the package manager and get Python 2.7 and IDLE.

View Article
Write a Simple Program in Python

Article / Updated 01-25-2022

Tradition dictates that Hello World! be the first program that you write when you're learning a new programming language like Python. You're following in the footsteps of many great programmers when you create this project. To create your Hello World! program, follow these steps: Open your Start menu and choose Python (command line). You should get a prompt that looks like >>>. At the moment, you're doing everything in interactive mode in the Python interpreter. That's where the >>> comes in. Python shows you >>> when you're supposed to type something. At the prompt, type the following. Use a single quote at the start and the end — it's beside the Enter key: print('Hello World!') Press the Enter key. Python runs the code you typed. You see the output shown in Figure 1. Congratulations — you've written your first program. Welcome to the Python-programmers-in-training club. If you don't see what's in Figure 1, check that you typed in the text from Step 2 exactly as it's written: Check that the parentheses and single quotes are in the right places. Check that for each opening parenthesis there is a closing parenthesis. (Otherwise, you're left hanging. Check that for each opening quote there's a closing quote. Programming languages have their own grammar and punctuation rules. These rules are the language's syntax. Humans, can work most stuff out even if perfect not you're is grammar (See? You figured out what that sentence was trying to say), but Python pretty much freaks out if you get the syntax wrong.

View Article
Use Python to Help with Your Math Homework

Article / Updated 03-26-2016

Python can do fractions so you can check your homework answers. Use the fractions module, and its Fraction object, specifying the numerator and denominator. To get one-half, type fractions.Fraction(1, 2). For four-fifths, type fractions.Fraction(4, 5): >>> import fractions >>> one_half = fractions.Fraction(1, 2) >>> one_fifth = fractions.Fraction(1, 5) Fractions can do normal fraction calculations (including multiplication and division) for you: >>> one_half+one_fifth Fraction(7, 10) >>> one_half-one_fifth Fraction(3, 10) >>> one_half*one_fifth Fraction(1, 10) >>> one_half/one_fifth Fraction(5, 2)

View Article
Python 2.7 Keyword Subset and Examples

Article / Updated 03-26-2016

Programming is an important skill. Python will serve you well for years to come. The tables here give you the core words, built-ins, standard library functions, and operators that you'll use most when you're coding with Python. Python Core Words KeywordSummaryExample and Logical operator to test whether two things are both True. andx>2 and x<10 as Assign a file object to a variable. Used with with.Let your code refer to a module under a different name (also called an alias). Used with import. with open(<name of file>,<file mode>) as <object name>:import cPickle as pickle break Stop execution of a loop. for i in range(10): if i%2 ==0: break class Define a custom object. class <name of class>(object): ""Your docstring"" class MyClass(object): ""A cool function."" continue Skip balance of loop and begin a new iteration. for i in range(10): if i%2 ==0: continue def Define a function. def <name of function>(): ""Your docstring"" def my_function(): ""This does... "" elif Add conditional test to an if clause. See if. else Add an alternative code block. See if. for Create a loop which iterates through elements of a list (or other iterable). for <dummy variable name> in <sequence>:for i in range(10): from Import specific functions from a module without importing the whole module. from <module name> import <name of function or object>from random import randint global Make a variable global in scope. (If a variable is defined in the main section, you can change its value within a function.) global x if Create a condition. If the condition is True, the associated code block is executed. Otherwise, any elif commands are processed. If there are none, or none are satisfied, execute the else block if there is one. if : [elif : , ...][else: ]if x == 1: print("x is 1")elif x == 2: print("x is 2")elif x > 3: print("x is greater than 3")else print("x is not greater than 3, nor is it 1 one or 2") import Use code defined in another file without retyping it. import <name of module>import random in Used to test whether a given value is one of the elements of an object. 1 in range(10) is Used to test whether names reference the same object. x = Nonex is None # faster thanx == None lambda Shorthand function definition. Usually used where a function needs to be passed as an argument to another function. lamda :times = lambda x, y: x*ycommand=lambda x: self.draw_line(self.control_points) not Logical negation, used to negate a logical condition. Don't use for testing greater than, less than, or equal. 10 not in range(10) or Logical operator to test whether at least one of two things is True. orx<2 or x>10 pass Placeholder keyword. Does nothing but stop Python complaining that a code block is empty. for i in range (10): pass print Output text to a terminal. print("Hello World!") return Return from the execution of a function. If a value is specified, return that value, otherwise return None. return return x+2 while Execute a code block while the associated condition is True. while :while True: pass with Get Python to manage a resource (like a file) for you. with open(,) as : Extend Python's core functionality with these built-ins. Python Built-ins Built-inNotesExample False Value, returned by a logical operation or directly assigned. ok_to_continue = Falseage = 16old_enough = age >=21(evaluates comparison age>=21 and assigns the result to old_enough) None Value used when representing the absence of a value or to initialise a variable which will be changed later. Returned by functions which do not explicitly return a value. x = None True Value, returned by a logical operation. ok_to_continue = Trueage = 16old_enough = age >=21(evaluates comparison age>=21 and assigns the result to old_enough) __name__ Constant, shows module name. If it's not "__main__", the code is being used in an import. if __name__=="__main__": dir List attributes of an item. dir(<object name>) enumerate Iterate through a sequence and number each item. enumerate('Hello') exit Exit Python (Command Line) interpreter. exit() float Convert a number into a decimal, usually so that division works properly. 1/float(2) getattr Get an attribute of an object by a name. Useful for introspection. getattr(<name of object>, <name of attribute>) help Get Python docstring on object. help(<name of object>)help(getattr) id Show the location in the computer's RAM where an object is stored. id(<name of object>)id(help) int Convert a string into an integer number. int('0') len Get the number of elements in a sequence. len([0,1]) object A base on which other classes can inherit from. class CustomObject(object): open Open a file on disk, return a file object. open(, )open('mydatafile.txt', 'r') # read(opens a file to read data from)open('mydatafile.txt', 'w') # write(creates a new file to write to, destroys any existing file with the same name)open('mydatafile.txt', 'a') # append(adds to an existing file if any, or createsa new one if none existing already) print Reimplementation of print keyword, but as a function.Need to import from the future to use it (srsly!) from future import print_functionprint ('Hello World!') range Gives numbers between the lower and upper limits specified (including the lower, but excluding the upper limit). A step may be specified. range(10)range(5,10)range(1,10,2) raw_input Get some text as a string from the user, with an optional prompt. prompt = 'What is your guess? 'players_guess = raw_input(prompt) str Convert an object (usually a number) into a string (usually for printing). str(0) type Give the type of the specified object. type(0)type('0')type([])type({})type(()) Use the work that others have already done. Try these modules from the Python standard library. Selected Functions from the Standard Library ModuleWhat It DoesSample Functions/Objects os.path Functions relating to files and file paths. os.path.exists() pickle, cPickle Save and load objects to/from a file. pickle.load(), pickle.dump(, ) random Various functions relating to random numbers. random.choice(), random.randint(, ), random.shuffle() String Stuff relating to strings. string.printable sys Various functions related to your computer system. sys.exit() Time Time-related functions. time.time() Tkinter User interface widgets and associated constants. Tkinter.ALLTkinter.BOTHTkinter.CENTERTkinter.ENDTkinter.HORIZONTALTkinter.LEFTTkinter.NWTkinter.RIGHTTkinter.TOPTkinter.YTkinter.Button(,text=)Tkinter.Canvas(, width=, height=)Tkinter.Checkbutton(, text=)Tkinter.Entry(, width=),Tkinter.Frame()Tkinter.IntVar()Tkinter.Label(, text = )Tkinter.mainloop()Tkinter.Menu()Tkinter.OptionMenu(, None, None)Tkinter.Scale(, from_=, to=)Tkinter.Scrollbar()Tkinter.StringVar()Tkinter.Tk() Add, subtract, divide, multiply, and more using these operators. Python Operators OperatorNameEffectExamples + Plus Add two numbers.Join two strings together. Add: >>> 1+12Join: >>> 'a'+'b''ab' – Minus Subtract a number from another.Can't use for strings. >>> 1-10 * Times Multiply two numbers.Make copies of a string. Multiply: >>> 2*24Copy: >>> 'a'*2'aa' / Divide Divide one number by another.Can't use for strings. 1/2 # integer division:Answer will be rounded down.1/2.0 # decimal division1/float(2) # decimal division % Remainder (Modulo) Give the remainder when dividing the left number by the right number.Formatting operator for strings. >>> 10%31 ** Power x**y means raise x to the power of y.Can't use for strings. >>> 3**29 = Assignment Assign the value on the right to the variable on the left. >>> a = 1 == Equality Is the left side equal to the right side? Is True if so; is False otherwise. >>> 1 == 1True>>> 'a' == 'a'True != Not equal Is the left side not equal to the right side? Is True if so; is False otherwise. >>> 1 != 1False>>> 1 != 2True>>> 'a' != 'a'True > Greater than Is the left side greater than the right side?>= means greater than or equal to >>> 2 > 1True < Less than Is the left side less than the right side?<= means less than or equal to >>> 1 < 2True & (or and) And Are both left and right True?Typically used for complex conditions where you want to do something if everything is True:while im_hungry and you_have_food: >>> True & TrueTrue>>> True and FalseFalse >>> True & (1 == 2)False | (or or) Or Is either left or right True?Typically used for complex conditions where you want at least one thing to be True:while im_bored or youre_bored: >>> True | FalseTrue>>> True or FalseTrue>>> False | FalseFalse>>> (1 == 1) | FalseTrue

View Article
Using Tkinter Widgets in Python

Article / Updated 03-26-2016

Tkinter in Python comes with a lot of good widgets. Widgets are standard graphical user interface (GUI) elements, like different kinds of buttons and menus. Most of the Tkinter widgets are given here. Label Widget A Label widget shows text to the user. You can update the widget programmatically to, for example, provide a readout or status bar. import Tkinter parent_widget = Tkinter.Tk() label_widget = Tkinter.Label(parent_widget, text="A Label") label_widget.pack() Tkinter.mainloop() Button Widget A Button can be on and off. When a user clicks it, the button emits an event. Images can be displayed on buttons. import Tkinter parent_widget = Tkinter.Tk() button_widget = Tkinter.Button(parent_widget, text="A Button") button_widget.pack() Tkinter.mainloop() Entry Widget An Entry widget gets text input from the user. import Tkinter parent_widget = Tkinter.Tk() entry_widget = Tkinter.Entry(parent_widget) entry_widget.insert(0, "Type your text here") entry_widget.pack() Tkinter.mainloop() Radiobutton Widget A Radiobutton lets you put buttons together, so that only one of them can be clicked. If one button is on and the user clicks another, the first is set to off. Use Tkinter variables (mainly Tkinter.IntVar and Tkinter.StringVar) to access its state. import Tkinter parent_widget = Tkinter.Tk() v = Tkinter.IntVar() v.set(1) # need to use v.set and v.get to # set and get the value of this variable radiobutton_widget1 = Tkinter.Radiobutton(parent_widget, text="Radiobutton 1", variable=v, value=1) radiobutton_widget2 = Tkinter.Radiobutton(parent_widget, text="Radiobutton 2", variable=v, value=2) radiobutton_widget1.pack() radiobutton_widget2.pack() Tkinter.mainloop() Radiobutton Widget (Alternate) You can display a Radiobutton without the dot indicator. In that case it displays its state by being sunken or raised. import Tkinter parent_widget = Tkinter.Tk() v = Tkinter.IntVar() v.set(1) radiobutton_widget1 = Tkinter.Radiobutton(parent_widget, text="Radiobutton 1", variable=v, value=1, indicatoron=False) radiobutton_widget2 = Tkinter.Radiobutton(parent_widget, text="Radiobutton 2", variable=v, value=2, indicatoron=False) radiobutton_widget1.pack() radiobutton_widget2.pack() Tkinter.mainloop() Checkbutton Widget A Checkbutton records on/off or true/false status. Like a Radiobutton, a Checkbutton widget can be displayed without its check mark, and you need to use a Tkinter variable to access its state. import Tkinter parent_widget = Tkinter.Tk() checkbutton_widget = Tkinter.Checkbutton(parent_widget, text="Checkbutton") checkbutton_widget.select() checkbutton_widget.pack() Tkinter.mainloop() Scale Widget: Horizontal Use a Scale widget when you want a slider that goes from one value to another. You can set the start and end values, as well as the step. For example, you can have a slider that has only the even values between 2 and 100. Access its current value by its get method; set its current value by its set method. import Tkinter parent_widget = Tkinter.Tk() scale_widget = Tkinter.Scale(parent_widget, from_=0, to=100, orient=Tkinter.HORIZONTAL) scale_widget.set(25) scale_widget.pack() Tkinter.mainloop() Scale Widget: Vertical A Scale widget can be vertical (up and down). import Tkinter parent_widget = Tkinter.Tk() scale_widget = Tkinter.Scale(parent_widget, from_=0, to=100, orient=Tkinter.VERTICAL) scale_widget.set(25) scale_widget.pack() Tkinter.mainloop() Text Widget Use a Text widget to show large areas of text. The Text widget lets the user edit and search. import Tkinter parent_widget = Tkinter.Tk() text_widget = Tkinter.Text(parent_widget, width=20, height=3) text_widget.insert(Tkinter.END, "Text Widgetn20 characters widen3 lines high") text_widget.pack() Tkinter.mainloop() LabelFrame Widget The LabelFrame acts as a parent widget for other widgets, displaying them with a title and an outline. LabelFrame has to have a child widget before you can see it. import Tkinter parent_widget = Tkinter.Tk() labelframe_widget = Tkinter.LabelFrame(parent_widget, text="LabelFrame") label_widget=Tkinter.Label(labelframe_widget, text="Child widget of the LabelFrame") labelframe_widget.pack(padx=10, pady=10) label_widget.pack() Tkinter.mainloop() Canvas Widget You use a Canvas widget to draw on. It supports different drawing methods. import Tkinter parent_widget = Tkinter.Tk() canvas_widget = Tkinter.Canvas(parent_widget bg="blue", width=100, height= 50) canvas_widget.pack() Tkinter.mainloop() Listbox Widget Listbox lets the user choose from one set of options or displays a list of items. import Tkinter parent_widget = Tkinter.Tk() listbox_entries = ["Entry 1", "Entry 2", "Entry 3", "Entry 4"] listbox_widget = Tkinter.Listbox(parent_widget) for entry in listbox_entries: listbox_widget.insert(Tkinter.END, entry) listbox_widget.pack() Tkinter.mainloop() Menu Widget The Menu widget can create a menu bar. Creating menus can be hard, especially if you want drop-down menus. To do that, you use a separate Menu widget for each drop-down menu you're creating. import Tkinter parent_widget = Tkinter.Tk() def menu_callback(): print("I'm in the menu callback!") def submenu_callback(): print("I'm in the submenu callback!") menu_widget = Tkinter.Menu(parent_widget) submenu_widget = Tkinter.Menu(menu_widget, tearoff=False) submenu_widget.add_command(label="Submenu Item1", command=submenu_callback) submenu_widget.add_command(label="Submenu Item2", command=submenu_callback) menu_widget.add_cascade(label="Item1", menu=submenu_widget) menu_widget.add_command(label="Item2", command=menu_callback) menu_widget.add_command(label="Item3", command=menu_callback) parent_widget.config(menu=menu_widget) Tkinter.mainloop() OptionMenu Widget The OptionMenu widget lets the user choose from a list of options. To use the OptionMenu the right way, you'll probably need to bind it to a separate callback that updates other information based on the user's selection. Get the currently selected value with its get method. import Tkinter parent_widget = Tkinter.Tk() control_variable = Tkinter.StringVar(parent_widget) OPTION_TUPLE = ("Option 1", "Option 2", "Option 3") optionmenu_widget = Tkinter.OptionMenu(parent_widget, control_variable, *OPTION_TUPLE) optionmenu_widget.pack() Tkinter.mainloop()

View Article
How to Interrupt a Program in Python

Article / Updated 03-26-2016

Usually you get called rude if you interrupt. Not in programming. Are you ready to create a program that never finishes by itself (called an infinite loop)? This section shows you how to force it to stop. Forcing a stop is useful when your program locks up and won't respond. The trick is to press Ctrl+C (the Ctrl key and the C key at the same time; don't press the Shift key). Make sure the Python window is active (by clicking the window) when you do — or you might close the wrong program! Here's how you write an infinite loop program: Type while True: and press Enter. Press the spacebar four times. Type pass. Press Enter twice. This is what you'll see: >>> while True: … pass … The Python interpreter is unresponsive. If you try to get it to assign or print something, nothing happens. It lays there like a lump. The usual >>> prompt isn’t there. You may also hear your computer laboring. Quick: Press Ctrl+C to break out of the loop and get control back. You get this when you do it: >>> while True: … pass … ^CTraceback (most recent call last): File "", line 1, in KeyboardInterrupt >>>

View Article
How to Name Functions in Python

Article / Updated 03-26-2016

Functions are extremely useful and powerful tools in your programming toolbox because they allow you to separate your program into meaningful blocks. All the built-ins in Python are functions, as is everything in the standard library. The rules for naming a function are a lot like rules for naming a variable: They must start with a letter or an underscore: _. They should be lowercase. They can have numbers. They can be any length (within reason), but keep them short. They can't be the same as a Python keyword. They can have the same name as an existing function (including a built-in), but avoid this for now. The function print_hello_world is very basic. It only does one thing. It can't respond to different circumstances because no information is passing into the function when you call it. This is fine if you need to do the same thing all the time. Functions are even more powerful, though, because you can communicate with them and they can do different things depending on the information. You could change this function and send it different messages to print.

View Article
How to Handle Your Functions in Python

Article / Updated 03-26-2016

Functions in programming are a simple way to group together actions. With them you can do some groups of actions repeatedly without having to retype all the code. You save typing, and it's easier to think about how to structure your program and to update it. One problem with these approaches: They don't let you reuse code in other circumstances. Besides comments, which get messy as programs get larger, you have no obvious way to tell what part of the code does what. Think of when your parents tell you to get ready for school. They might say, "Get up, get dressed, have some breakfast, put your homework in your bag, put your lunch in your bag, brush your teeth." When they say, "Get ready for school," they're wrapping all those separate activities into one thing, like a get_ready function. They're also moving from the particular (detailed instructions on what to do and how to do it) to the general (getting ready). This is called abstraction. Whenever you move from thinking less about details, you're being more abstract (or you've accidentally gone to sleep). When you abstract things, you can plan with general concepts but tackle each separate task. Plan your own programs using functions as your level of abstraction, then tackle what each function does separately. Divide, then conquer! Functions let you explain what does what, and functions let you reuse your code. To use a function, you must Define the function itself Invoke, or call, the function Here's a simple example that reworks your Hello World! program using a function. Open IDLE and type this in the Shell window: >>> def print_hello_world(): ""Hello World as a function"" print('Hello World!') Remember to press Enter twice to return to the command prompt. It doesn't do anything. A bit pointless? Sort of. You're defining the function (using the def keyword). Now, you must call the function to make it run: >>> print_hello_world() Hello World! As you can see from Figure 1, Python will call the function if you write the function's name followed by parentheses. This means that as Python flows through your program, when it reaches the function call it continues at the function definition and runs through the code in that function's code block. Figure 1: Program flows into and out of the function. A function's code block is the line following the def statement up to (but not including) the next line that's indented the same as the def statement. You can see some code blocks pointed out in Figure 2. When the Python reaches the end of the function, it skips back to the spot where the call occurred (back there with the parentheses). do_guess_round code block holds the while loop." width="535"/>Figure 2: The do_guess_round code block holds the while loop. Including the parentheses with the function call is important. If you leave them out Python doesn't call the function. Instead it tells you about the function: >>> print_hello_world Here it's telling you that print_hello_world is a function, and that its name is print_hello_world. The bit at the end is where in memory the Python keeps the function.

View Article
How to Indent and Dedent Your Python Code

Article / Updated 03-26-2016

You're going to have to change the number of spaces in front of one or more lines of code. It's common in programming like Python. Moving them in is indenting. Moving them out is dedenting (or deindenting). For example, if you want to move a print statement from the main part of the program into the code block of a loop, you need to indent it. To move it out of the code block of a loop, you need to deindent it. IDLE has tools to indent and dedent code blocks. Try those -denting tools: Start with some code. Here's some: ""This is just a test file"" DEBUG = True print('Hello World! from the editor') # hashes are used for comments too "" You usually use hashes at the end of a line rather than for a block comment like this one. "" ############################################################### # Nevertheless you can still use hashes for block comments # Especially if you want to have a specific visual effect ############################################################### if DEBUG: print('I think I need another print statement in this code block') print('See that the comments were ignored?') # even this one Select the lines to indent. Click and drag with your mouse to select the code (the last print statement), or press Shift while using your arrow keys. Choose Format → Indent Region. Ctrl+] also works. Make sure the code's indented into a valid code block. Indentation is meaningful to Python. You'll get a syntax error if you have the wrong level of indent. It's best to use four spaces of indent for each code block level. If you use another number of spaces (2, 6, 8), that's fine. The important thing is that all the code in the code block must have the same number of spaces. To go the other way, select the code and choose File → Dedent Region (or press Ctrl+[).

View Article
page 1
page 2