Python Strings Using Command Line Environment

Using The Python Command Line Interface

The python interpreter shell can be invoked by typing “python” on the terminal on Linux, Mac OS and other POSIX systems. For windows systems, the postfix “.exe” is needed.

It is easy to execute python scripts on the command line or run python code in the shell.

The python command has several flags for different options.

Python Command

Flags

Python Flags
Name Flag Example
Help -? python -?
Help -h python -h
Help –help python –help
Version -V python -V
Version –version python –version
Run code -c python -c “print(‘Hello World’)”
Run module -m python -m mymodule
Python CLI Recommend if installed 2024

# Strings
str1 = "Hello World" # Double Quotes
str2 = 'Hello World!' # Single Quotes
print (str1, str2) # Output Multiple Variables

# Quotes Inside Strings
str1 = "It’s easy" # Double Quotes With Single Quote
str2 = "Call me 'Johnny'" # Double Quotes With Single Quotes
str3 = 'Call me "Johnny"' # Single Quotes With Double Quotes
print(str1, str2, str3) # Output Multiple Variables

# Multiline Strings
str1 = """This is a double quoted
multiple line string
spanning 3 rows."""
print(str1) # Output

# Slicing Strings
str1 = "Hello, World!" # Double Quotes
print (str1[2:5]) # Prints from position 2 to position 5

# Concatenate Strings
str1 = "Hello"
str2 = "World"
str3 = str1 + " " + str2
print(str3) # Displays Hello World

# F-Strings Format Strings
age = 24
name = "John"
combined = f"My name is {name}, and I am {age} years old"
print(combined)

# Escape Characters
str1 = "My name is \"Johnny\" but you can call me \"John\"."
print(str1)

Python CLI Screen
Python Command Line Interface Start Screen

Python CLI Code
Python Command Line Interface Typed Code

Python CLI One-Liner
Python Command Line Interface Execute One-Liner Code


Usage

You can use the interactive shell after installing Python. The initial screen displays the version and help information. You can use various flags on the command line interface to execute Python code.

Open Source

Python is licensed under the Python Software Foundation License. This allows commercial use, modification, distribution, and allows making derivatives proprietary. Since it is made with Python, it makes it easier to contribute and modify.

Learning Python:

Course is optimized for your web browser on any device.

OjamboShop.com Learning Python
OjamboShop.com Learning Python Interactive Course

Limited Time Offer:

OjamboShop.com is offering 20% off coupon code SCHOOL for Learning Python until End Day 2024.

Conclusion:

Install the Python by compiling from source or downloading binaries for your device. Use Python command line interface to create custom scripts or code.

Take this opportunity to learn Python programming language by making a one-time purchase at Learning Python. A web browser is the only thing needed to learn Python in 2024 at your leisure. All the developer tools are provided right in your web browser.

References: