Guide to Python (University at Buffalo Version)
Chapter 1: Introduction to Python
Python is a popular general-purpose scripting language that is especially suited computer program development. (See python.org). Python is available for for Windows, Linux/UNIX, macOS, and many other operating systems/platforms from the Python Download site.
Hello World!
Most beginning programmers start with the standard "Hello World" code:
A Python Hello World Code Example
Python 3.12.8 (tags/v3.12.8:2dc476b, Dec 3 2024, 19:30:04) [MSC v.1942 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print(Hello!)
helloworld.py
The output would look like this:
Hello! >>>

Python Comments
Python provides a few different way to add comments to your code. You can use multi-line comments or inline (single line) comments or Python Docstrings comments. Comments should be used to explain what your code is doing. Comments should be used to provide a description of each function including whether there are parameters and whther the function returns a value or not.
""" Assignment: My First Python program Author: Your Name Here Date: Month Day, Year file was last edited Editor: Notepad++ or TextWrangler or idle or whatever editor you used """ # Print hello string def printName(): """ prompt for a name then print the hello string """ name = input("Enter your name: ") print('Hello ' + name) # Call the printName function. printName()
""" Python Docstring Commments """ Print hello string def printName(): """ prompt for a name then print the hello string """ Prompt for a name. name = input("Enter your name: ") print('Hello ' + name) print(printName.__doc__) help(printName) # Call the printName function. printName()
input
Function CodeGetting User Input
A common task is to prompt the user to input some data. You can use the Python input()
function to prompt the user tp enter some data and store their response in a variable.
# get_input.py # Prompt for a name. name = input("Enter your first name: ") # Display a "hello" message. print('Hello ' + name + '!')
input
Function Code>>> Enter your name: Jim Hello Jim!
input
Function Output