• About
  • Contact
  • Cookie
  • Disclaimer
  • Privacy Policy
  • Change the purpose of use

Tnhelearning.edu.vn - Various useful general information portal

  • Photo
  • Bio
  • How To
  • Tech

How to Start Programming in Python

November 27, 2023 by admin Category: How To

You are viewing the article How to Start Programming in Python  at Tnhelearning.edu.vn you can quickly access the necessary information in the table of contents of the article below.

Python is an incredibly versatile programming language that has gained popularity for its simplicity and readability. Whether you are a beginner or an experienced programmer, Python serves as an excellent starting point to master the fundamentals of coding. In this guide, we will explore the essential steps to kickstart your programming journey in Python. From setting up your environment to understanding basic concepts and writing your first program, this introduction will provide you with a solid foundation to start programming in Python. So, let’s dive into the world of Python and embark on an exciting coding adventure!

X

wikiHow is a “wiki” site, which means that many of the articles here are written by multiple authors. To create this article, 48 people, some of whom are anonymous, have edited and improved the article over time.

This article has been viewed 33,338 times.

Want to learn programming? The process of getting used to programming can be daunting and make you think that you need to go to school seriously to do it. With some languages, this is sometimes true. But there are also many programming languages that only take one to two days for you to grasp the basics of them. Python [1] X Research Source is one such language. In just a few minutes, you can run a basic Python program. Read step 1 below to learn how.

Table of Contents

  • Steps
    • Install Python (for Windows OS)
    • Learn the basics
    • Use the interpreter like a calculator
    • Create your first program
    • Build advanced programs
  • Advice

Steps

Install Python (for Windows OS)

Image titled 167107 1

Image titled 167107 1

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/1/19/167107-1.jpg/v4-728px-167107-1.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/1/19/167107-1.jpg/v4-728px-167107-1.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Download Python for Windows system. The Windows Python interpreter can be installed for free from the Python website. Please make sure that you have downloaded the correct version for your operating system.

  • You should download the latest version available, at the time this article was written, it was version 3.4.
  • Python is available in OS X and Linux. You don’t need to install any other Python related software anymore. However, you should probably install a word processor program.
  • Most Linux distributions and versions of OS X still use Python 2.X. There are some minor differences between version 2 and version 3, most notably a change in the “print” structure. If you want to install a newer version of Python for OS X or Linux, you can download the file from the Python website.
Image titled 167107 2

Image titled 167107 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/9/94/167107-2.jpg/v4-728px-167107-2.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/9/94/167107-2.jpg/v4-728px-167107-2.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Install the Python interpreter. Most users can install the interpreter without changing any settings. You can merge Python into the built-in command line interpreter in Windows (Command Prompt) by enabling the last option in the list of available modules. [2] X Research Source
Image titled 167107 3

Image titled 167107 3

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/1/1b/167107-3.jpg/v4-728px-167107-3.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/1/1b/167107-3.jpg/v4-728px-167107-3.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Install a word processor program. Whether you can write Python programs with Notepad or TextEdit, it’s much easier to read and code using a specialized text editor. There are many free editing programs to choose from, such as Notepad++ (Windows), TextWrangler (Mac) or Jedit (for any operating system).
Image titled 167107 4

Image titled 167107 4

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/2/22/167107-4.jpg/v4-728px-167107-4.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/2/22/167107-4.jpg/v4-728px-167107-4.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Check your settings. Open Command Prompt (Windows) or Terminal (Emulator – Mac/Linux) and type python . Python will load and display the version number. You will be redirected to the Python interpreter command line application, represented as: >>> .

  • Type print("Hello World!") and press the ↵ Enter key. Text Hello World! will be displayed just below the Python command line.

Learn the basics

Image titled 167107 5

Image titled 167107 5

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/1/1d/167107-5.jpg/v4-728px-167107-5.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/1/1d/167107-5.jpg/v4-728px-167107-5.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Please understand that Python does not need to be compiled. Python is an interpreted language, which means you can run the program as soon as you make changes to the file. As a result, iteration, editing, and problem-solving programs run much faster than in other languages.

  • Python is one of the easiest languages to learn and you can run a simple program in just a few minutes.
Image titled 167107 6

Image titled 167107 6

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/1/11/167107-6.jpg/v4-728px-167107-6.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/1/11/167107-6.jpg/v4-728px-167107-6.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Explore with the interpreter. You can use the interpreter to test the code right away without having to add it to your program before you can test it. It’s great for learning how a command works or writing a draft program.
Image titled 167107 7

READ More:   How to Avoid Rattlesnake Attacks

Image titled 167107 7

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/2/27/167107-7.jpg/v4-728px-167107-7.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/2/27/167107-7.jpg/v4-728px-167107-7.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Learn how Python handles objects and variables. Python is an object-oriented language, meaning everything in the program is treated as an object. Also, you don’t need to specify the variable at the start of the program (which you can do at any time) and you don’t need to specify the variable type (integer, string, etc.).

Use the interpreter like a calculator

Doing a few simple math functions will familiarize you with Python’s syntax and how numbers and strings are handled.

Image titled 167107 8

Image titled 167107 8

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/f/fc/167107-8.jpg/v4-728px-167107-8.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/f/fc/167107-8.jpg/v4-728px-167107-8.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Start the interpreter. Open your Command Prompt or Terminal. Type the line python at the prompt and press the ↵ Enter key. The Python interpreter will be loaded and redirect you to the Python command line interpreter application ( >>> ).

  • If you haven’t combined Python with an existing command-line interpreter, you’ll have to navigate to the Python directory to run the interpreter.
Image titled 167107 9

Image titled 167107 9

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/e/e5/167107-9.jpg/v4-728px-167107-9.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/e/e5/167107-9.jpg/v4-728px-167107-9.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Perform basic arithmetic operations. You can use Python to do it easily. Check out some examples in the box below on how to use the calculate function. Note: in Python code, # is used to refer to paragraphs that are followed by interpretation and, therefore, will not be included in the interpreter.

 >>> 3 + 7 10 >>> 100 - 10 * 3 70 >>> ( 100 - 10 * 3 ) / 2 # Division always returns standard floating point (decimal) 35.0 >>> ( 100 - 10 * 3 ) // 2 # Integer division (two slashes) removes any decimals from the result. 35 >>> 23 % 4 # This command calculates remainder of division 3 >>> 17.53 * 2.67 / 4.1 11.41587804878049 
Image titled 167107 10

Image titled 167107 10

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/0/0e/167107-10.jpg/v4-728px-167107-10.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/0/0e/167107-10.jpg/v4-728px-167107-10.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Calculate exponentiation. You can use the ** operator to represent exponentiation. Python can calculate large numbers quickly. Refer to the example in the box below.

 >>> 7 ** 2 # 7 squared 49 >>> 5 ** 7 # 5 power 7 78125 
Image titled 167107 11

Image titled 167107 11

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/f/fb/167107-11.jpg/v4-728px-167107-11.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/f/fb/167107-11.jpg/v4-728px-167107-11.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Create and manipulate the same variables. You can assign variables in Python to perform simple algebraic calculations. This can be seen as a pretty good introduction to how to assign variables in a Python program. Variables are assigned via the = sign. For better understanding, see the example in the box below.

 >>> a = 5 >>> b = 4 >>> a * b 20 >>> 20 * a // b 25 >>> b ** 2 16 >>> wide = 10 # Variable can be a string literal any order >>> height = 5 >>> width * height 50 
Image titled 167107 12

Image titled 167107 12

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/c/cf/167107-12.jpg/v4-728px-167107-12.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/c/cf/167107-12.jpg/v4-728px-167107-12.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Close the interpreter. Once you’re done, you can close the interpreter and return to the command-line interpreter application by pressing Ctrl + Z (Windows) or Ctrl + D (Linux/Mac) and then pressing ↵ Enter . You can also type quit() and press ↵ Enter .

Create your first program

Image titled 167107 13

Image titled 167107 13

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/4/40/167107-13.jpg/v4-728px-167107-13.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/4/40/167107-13.jpg/v4-728px-167107-13.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Open a text editor. You can quickly create test programs to familiarize yourself with the basics of creating and saving programs and running them through the interpreter. It will also help you check if the interpreter is installed correctly.
Image titled 167107 14

Image titled 167107 14

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/d/d8/167107-14.jpg/v4-728px-167107-14.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/d/d8/167107-14.jpg/v4-728px-167107-14.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Create a “print” command. “Print” is a basic function in Python, used to display information at the terminal in a program. Note: “print” is one of the biggest changes since moving from Python 2 to Python 3. In Python 2, you just need to type “print” before the content you want to display. In Python 3, “print” became a function. Therefore, you will have to type “print()”, with the content you want to display enclosed in brackets.
Image titled 167107 15

Image titled 167107 15

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/7/70/167107-15.jpg/v4-728px-167107-15.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/7/70/167107-15.jpg/v4-728px-167107-15.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Add your sentence. One of the most popular ways to test a programming language is to display “Hello World!”. Put this sentence in the “print()” statement, including the quotes:

 print ( "Hello World!" )
  • Unlike many other languages, you don’t need to use the ; to end the command. You also don’t need braces ( {} ) to lock a block of commands. Instead, just indenting is enough to show what is contained in the command block.
Image titled 167107 16

Image titled 167107 16

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/1/15/167107-16.jpg/v4-728px-167107-16.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/1/15/167107-16.jpg/v4-728px-167107-16.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Save file. Click the File menu in your editor and choose Save As. In the drop-down menu below the name box, select the Python file type. If using Notepad (not recommended), select “All Files” and then add “.py” to the filename.

  • Make sure you save the file in an easily accessible location because you will have to find it in the command line interpreter.
  • In this example, the file is saved as “hello.py”.
READ More:   How to Make Tomato Juice
Image titled 167107 17

Image titled 167107 17

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/0/02/167107-17.jpg/v4-728px-167107-17.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/0/02/167107-17.jpg/v4-728px-167107-17.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Run the program. Open Command Prompt or Terminal and navigate to the location where you saved the file. Once there, run the file by typing hello.py and then pressing the ↵ Enter key. You will see the words Hello World! is displayed just below the prompt pointer.

  • Depending on how Python was installed and what version it is, you may have to type python hello.py or python3 hello.py to run the program.
Image titled 167107 18

Image titled 167107 18

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/0/09/167107-18.jpg/v4-728px-167107-18.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/0/09/167107-18.jpg/v4-728px-167107-18.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Test run regularly. One of the best things about Python is that you can try new programs right away. Opening a command-line interpreter and an editor at the same time is a good practice to do. When you save changes in the editor, you can run the program immediately from the command. This allows you to quickly check the changes that have just been made.

Build advanced programs

Image titled 167107 19

Image titled 167107 19

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/d/d4/167107-19.jpg/v4-728px-167107-19.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/d/d4/167107-19.jpg/v4-728px-167107-19.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Experiment with basic flow control structures. The flow control structure allows you to control what the program does based on certain conditions. [3] X Research Sources These constructs are the essence of Python, allowing you to create programs that perform different operations based on given input and conditions. While is a good starting point to get familiar with them. In the example below, you can use the while structure to calculate the Fibonacci sequence up to 100:

 # Each number in the Fibonacci sequence is # sum of the two numbers before it a , b = 0 , 1 while b < 100 : print ( b , end = ' ' ) a , b = b , a + b
  • The thread will run as long as (while) b is less than (<) 100.
  • The result will be 1 1 2 3 5 8 13 21 34 55 89
  • The end=' ' command displays the results on the same line instead of leaving the values in individual lines.
  • In this program there are some points that play a key role in creating complex programs in Python that you need to keep in mind as follows:
    • Highlight the line indent. The : indicates that the following lines will be indented and part of the block. In the example above, print(b) and a, b = b, a+b are parts of the while block. Backing in the right way is very important in ensuring the operation of the program.
    • Multiple variables can be defined on the same line. In the above example, a and b are both defined in the first line.
    • If you enter this program directly into the interpreter, you must add a blank line at the end of the program to let the interpreter know that the program has ended there.
Image titled 167107 20

Image titled 167107 20

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/7/78/167107-20.jpg/v4-728px-167107-20.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/7/78/167107-20.jpg/v4-728px-167107-20.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Build a function in the program. You can define functions for later use in your program. This is especially useful in cases where you need to use many functions within the confines of a larger program. In the example below, you can create a function to call the same Fibonacci sequence as above: [4] X Research Source

 def fib ( n ): a , b = 0 , 1 while a < n : print ( a , end = ' ' ) a , b = b , a + b print () # At the back of the program you can use the # Fibonacci function for a specified value of any fib ( 1000 )
  • It will return 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
Image titled 167107 21

Image titled 167107 21

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/7/75/167107-21.jpg/v4-728px-167107-21.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/7/75/167107-21.jpg/v4-728px-167107-21.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Build a more complex flow control program. The flow control structure allows you to set specific conditions to change the way your program behaves. This is especially important when dealing with user input. The following example will use if (if), elif (else if) (or if), and else (else) to create a simple user age evaluation program. [5] X Research Sources

 age = int ( input ( "Enter your name: " )) if age <= 12 : print ( "It's great being a kid!" ) elif age in range ( 13 , 20 ): print ( "You're a teenager!" !" ) else : print ( "It's time to be an adult" ) # If any of the above conditions are true # the corresponding message will be displayed. # If any of the conditions are not met, the message "else" (different) # will be displayed.
  • This program also introduces a few very important structures that are invaluable for a variety of applications:
    • input() – This command requires the user to input data from the keyboard. The user will see the message written in parentheses. In this example, input() is wrapped by the int() function – meaning that any input will be treated as an integer.
    • range() – This function can be used in a variety of ways. In this program, it checks whether the input number is between 13 and 20. The upper and lower bounds of the interval are not considered in the calculation.
READ More:   How to Create a Collage on Instagram
Image titled 167107 22

Image titled 167107 22

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/7/7f/167107-22.jpg/v4-728px-167107-22.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/7/7f/167107-22.jpg/v4-728px-167107-22.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Learn other conditional expressions. In the previous example, we used “less than or equal” (<=) to determine whether the entered age satisfies the condition. You can use the same expressions as in math, but type it a little differently:

Condition Expressions. [6] X Research Sources
Meaning Sign Python notation
Less < <
Bigger > >
Less than or equal ≤ <=
Greater than or equal to ≥ >=
Equal = ==
Not equal to ≠ !=
  • Continue learning. These are just the basics of Python. Despite being one of the simplest languages, if you want to dig deeper, Python is still very in-depth. The best way to continue learning is to keep building the program! Remember that you can quickly write any program straight into the interpreter and test the changes that have been made simply by running the program again from the command line.

    • There are many good books written about Python programming, including “Python for Beginners”, “Python Cookbook” and “Python Programming: An Introduction to Computer Science” (Python Programming: An Introduction to Computer Science).
    • There are many resources out there on the net, but many of them are still geared towards Python 2.X. You’ll probably have to slightly tweak every example they provide.
    • Many local schools offer classes in Python. Python is often taught in introductory classes because it is one of the easiest languages to learn.
  • Advice

    • Python is one of the simpler computer languages. However, in order to learn, you still have to give it a certain amount of effort. Having an understanding of basic algebra is also helpful because Python is heavily focused on math.
    X

    wikiHow is a “wiki” site, which means that many of the articles here are written by multiple authors. To create this article, 48 people, some of whom are anonymous, have edited and improved the article over time.

    This article has been viewed 33,338 times.

    Want to learn programming? The process of getting used to programming can be daunting and make you think that you need to go to school seriously to do it. With some languages, this is sometimes true. But there are also many programming languages that only take one to two days for you to grasp the basics of them. Python [1] X Research Source is one such language. In just a few minutes, you can run a basic Python program. Read step 1 below to learn how.

    In conclusion, starting programming in Python can be a rewarding and fulfilling journey. With its clear and readable syntax, extensive library support, and large community, Python is a great choice for beginners. By following a step-by-step approach, beginners can gradually build their programming skills and become proficient in Python. The key steps to start programming in Python include setting up the development environment, familiarizing yourself with the basics of the language, practicing with small projects, seeking help from online resources and communities, and continuously learning and improving. With dedication and persistence, anyone can become a proficient Python programmer and unlock a world of possibilities in the field of software development. So, don’t hesitate, start your Python programming journey today and embrace the power of this versatile language.

    Thank you for reading this post How to Start Programming in Python at Tnhelearning.edu.vn You can comment, see more related articles below and hope to help you with interesting information.

    Related Search:

    1. Python programming basics for beginners
    2. Step-by-step guide to get started with Python programming
    3. Top online resources for learning Python programming
    4. Essential tools and software for programming in Python
    5. Choosing the best Python IDE (Integrated Development Environment)
    6. Introduction to Python syntax and variables
    7. Exploring data types and operators in Python
    8. Understanding control flow and loops in Python programming
    9. Python functions and how to use them in programming
    10. Tips and best practices for efficient Python programming

    Related Posts

    How to Create Curved Text in Photoshop
    How to fall asleep faster
    How to Install FBReader to Read eBooks

    Category: How To

    Previous Post: « Top 999+ sunday wishes images – Amazing Collection sunday wishes images Full 4K
    Next Post: Top 999+ Game Shakers Wallpaper Full HD, 4K✅Free to Use »

    Copyright © 2025 · Tnhelearning.edu.vn - Useful Knowledge