What is the $ in python?

As a newbie to Python, I read a book written by Bill Lubanovich

I found something strange.

In this book, after saving simple code in test1.py, which is located

print("This standalone program works!") 

he says python can run it by typing

 $ python test1.py 

However, when I try to use this, a syntax error occurs.

Although I know that there are other methods, such as using exec (), which I found on this website, I want to know why the book uses this method, which does not work, at least for me.

+7
python shell
source share
3 answers

This means that you need to enter everything except $ in the terminal.

 python test1.py 

This is just an agreement. The authors also use > python test1.py and other notation.

I do not know which version of his book you are reading, but he mentions it in this version.

In the following example, $ is an example system prompt to enter a command such as python in a terminal window. Use it well for the code examples in this book, although your invitation may vary.

+12
source share

You do not have to enter $ .

$ represents a shell / terminal prompt. This is a character string that appears in your terminal when it expects input, although $ usually indicates some flavor of unix, for example. Linux

Your terminal will probably use a different prompt, for example

 [ user@localhost ~]$ 

Or, if you are using a Windows terminal, you can see:

 C:\> 

or

 C:\WINDOWS> 
+6
source share

The question was answered in the following stackoverflow article: What does the value of $ mean when running commands?

What does $ mean when running commands?

Python currently does not implement $ in its syntax. So this has nothing to do with Python. Instead, you see the ultimate hint of a Unix-based system (Mac, Linux, etc.).

So basically this is a terminal prompt, and you should only type: python test1.py without the $ sign. another example is ~ when using oh-my-zsh.

0
source share

All Articles