Printing result

Beginning Python Programming

Makzan, 2020 April.

print("something")

  • Printing output to command line interface
  • String representation
  • Formatted string: Putting variables into string

print()

# Defining variables

a = 1

b = 2
c = a + b

print(c)
print(b - a)

Print string

name = "Python"

# Concat string together
print("Hello" + name)

# Result:
> HelloPython

Print string

name = "Python"

# Concat string together
print("Hello" + name)

# Result:
> Hello Python

Formatted String

name = "Python"

print("Hello {}".format(name))

Formatted String

name = "Python"

print(f"Hello {name}")

Putting variables in string

temperture = 28
weather = "sunny"

# Concat strings together
print("It is " + weather + " today, " + str(temperture) + " Celsius degrees.")

😨

Putting variables in string

temperture = 28
weather = "sunny"

# Concat strings together
print("It is {} today, {} Celsius degrees.".format(weather, temperture))

😄

Putting variables in string

temperture = 28
weather = "sunny"

# Concat strings together
print(f"It is {weather} today, {temperture} Celsius degrees.")

😎

Defining Variables

  • Printing output to command line interface
  • String representation
  • Formatted string: Putting variables into string

Summary

Python: print('something')

By makzan

Python: print('something')

  • 1,012