Write a program in PyCharm: Create a new project, file, and write code. Run the program by clicking "Run 'main.py'" or using the keyboard shortcut. Set a breakpoint and use the "Debug" menu to execute to the breakpoint for debugging. Use the Variables panel to view variable values. Save your program and code faster with code completion and auto-import.
Writing a program in PyCharm
How toWrite a program in PyCharm?
1. Create a new project
- Open PyCharm
- Click "File">"New Project..."
- Select the project location and enter the project name
- Click "Create"
2. Create a new file
- In the "Project" panel, right-click the project folder
- Select "New">"Python File"
- Enter the file name and click "OK"
3. Write code
- In the code editor, enter the following code as an example:
<code class="python">print("Hello, world!")</code>
Copy after login
4. Run the program
- Click "Run 'main.py'" in the "Run" menu
- Alternatively, use the keyboard shortcut "Ctrl Shift F10" (Windows) Or "Cmd Shift F10" (Mac)
5. Debugging the program
- If an error occurs in the program, you can set breakpoints in the code. debug.
- Click the "Debugger" icon next to the line number to set a breakpoint
- Use "Run to Cursor" in the "Debug" menu to execute to the breakpoint
- Use " Variables" panel to view variable values
6. Save the program
- Click "File" > "Save" or use the keyboard shortcut " Ctrl S" (Windows) or "Cmd S" (Mac) to save the program.
Tip:
- PyCharm will automatically format the code for you.
- You can use code completion and automatic import functions to speed up coding.
- Explore the Settings menu to customize PyCharm’s appearance and settings.
The above is the detailed content of How to write programs in pycharm. For more information, please follow other related articles on the PHP Chinese website!