Skip to ContentGo to accessibility pageKeyboard shortcuts menu
OpenStax Logo

Learning Objectives

By the end of this section you should be able to

  • Name two examples of computer programs in everyday life.
  • Explain why Python is a good programming language to learn.

Computer programs

A computer is an electronic device that stores and processes information. Examples of computers include smartphones, tablets, laptops, desktops, and servers. Technically, a program is a sequence of instructions that a computer can run. Programs help people accomplish everyday tasks, create new technology, and have fun.

The goal of this book is to teach introductory programming and problem solving. Writing programs is a creative activity, inherently useful, and rewarding! No prior background in computer science is necessary to read this book. Many different types of programs exist, as shown in the illustration below. This book will focus on general purpose programs that typically run "behind the scenes."

Checkpoint

Online music streaming

Concepts in Practice

Computers and programs

1.
How many types of programs were described in the animation?
  1. 3
  2. 4
  3. 5
2.
What type of program will this book explain how to write?
  1. a tool that summarizes an individual's music preferences
  2. a mobile app for managing and sharing playlists of songs
  3. a website that shows the top artists for the past five years
3.
Which of the following devices is an example of a computer?
  1. wired headphones that plug into a smartphone
  2. remote control that pauses or skips the current song
  3. wi-fi speaker that streams music from Amazon
4.
Reading this book requires a strong background in mathematics.
  1. true
  2. false

Exploring further

Later chapters of this book show how to write analysis programs using real data. Example libraries that provide access to online streaming services include Spotipy, Pytube, and Pydora. Python-related tools often have the letters "py" in their name.

The Python language

This book introduces Python, one of the top programming languages today. Leading tech giants like Google, Apple, NASA, Instagram, Pixar, and others use Python extensively.

One reason why Python is popular is because many libraries exist for doing real work. A library is a collection of code that can be used in other programs. Python comes with an extensive Standard Library for solving everyday computing problems like extracting data from files and creating summary reports. In addition, the community develops many other libraries for Python. Ex: Pandas is a widely used library for data analysis.

Another reason why Python is popular is because the syntax is concise and straightforward. The syntax of a language defines how code must be structured. Syntax rules define the keywords, symbols, and formatting used in programs. Compared to other programming languages, Python is more concise and straightforward.

Example 1.1

Hello world in Python and Java

By tradition, Hello World is the first program to write when learning a new language. This program simply displays the message "Hello, World!" to the user. The hello world program is only one line in Python:

print("Hello, World!")

In contrast, the hello world program is five lines in Java (a different language).

public class Hello {
  public static void main(String[] args) {
   System.out.println("Hello, World!");
  }
}

However, conciseness is not the only consideration for which language is used. In different situations different languages may be more appropriate. Ex: Java is often used in Android development.

Checkpoint

Counting lines in a file

Concepts in Practice

Python vs Java syntax

5.
In general, Python programs are _____ than Java programs.
  1. faster
  2. longer
  3. shorter
6.
In the example programs above, what syntax required by Java is not required by Python?
  1. semicolons
  2. parentheses
  3. quote marks

Try It

Favorite song

The program below asks for your name and displays a friendly greeting. Run the program and see what happens. In the error message, EOF stands for End of File.

  • Many of the programs in this chapter expect input from the user. Enter your name in the Input box below the code. Run the program again, and see what changes.
  • Copy the following lines to the end of the program:


    song = input()
    print("Cool! I like", song, "too.")
    print("What is your favorite song?") song = input() print("Cool! I like", song, "too.")

  • The modified program reads two lines of input: name and song. Add your favorite song to the Input box below your name, and run the program again.

The next section of the book will explain how print() and input() work. Feel free to experiment with this code until you are ready to move on.

Citation/Attribution

This book may not be used in the training of large language models or otherwise be ingested into large language models or generative AI offerings without OpenStax's permission.

Want to cite, share, or modify this book? This book uses the Creative Commons Attribution License and you must attribute OpenStax.

Attribution information
  • If you are redistributing all or part of this book in a print format, then you must include on every physical page the following attribution:
    Access for free at https://openstax.org/books/introduction-python-programming/pages/1-introduction
  • If you are redistributing all or part of this book in a digital format, then you must include on every digital page view the following attribution:
    Access for free at https://openstax.org/books/introduction-python-programming/pages/1-introduction
Citation information

© Jul 30, 2024 OpenStax. Textbook content produced by OpenStax is licensed under a Creative Commons Attribution License . The OpenStax name, OpenStax logo, OpenStax book covers, OpenStax CNX name, and OpenStax CNX logo are not subject to the Creative Commons license and may not be reproduced without the prior and express written consent of Rice University.

This book utilizes the OpenStax Python Code Runner. The code runner is developed by Wiley and is All Rights Reserved.