|
1 | 1 | #=================================================================== |
2 | 2 | # PRINT() |
3 | 3 | # --------------------------------------- |
4 | | -# ...... |
5 | | -# ...... |
| 4 | +# The `print()` built-in Python function is used to display text |
| 5 | +# on the screen. It’s your main way to *communicate* with users |
| 6 | +# and check what your code is doing. |
| 7 | +# You’ll use it in almost every Python program! |
6 | 8 | #=================================================================== |
7 | 9 |
|
8 | | -print("Hi Python") |
9 | | -print('Hello Python') |
10 | | -# print("Hi') |
| 10 | +print("Hi Python") # Double quotes |
| 11 | +print('Hello Python') # Single quotes |
| 12 | +# print("Hi') |
11 | 13 |
|
| 14 | +# Print a Header with Separators |
12 | 15 | print("--------------------") |
13 | 16 | print(" LEARN PYTHON ") |
14 | 17 | print("--------------------") |
15 | 18 |
|
| 19 | +# For Fun! |
16 | 20 | print(" __") |
17 | 21 | print(" / _)") |
18 | 22 | print(" .-^^^-/ / ") |
19 | 23 | print("__/ / ") |
20 | 24 | print("<__.|_|-|_| ") |
21 | 25 |
|
22 | | -# Escape Sequences |
23 | | -# \" |
24 | | -# \' |
25 | | -# print("Hi "Python"") |
26 | | -print("Hi \"Python\"") |
27 | | -print('Hi 'Python'') |
28 | | -print('Hi "Python"') |
29 | | -print('Hi 'Python'') |
30 | | -print('Hi \'Python\'') |
31 | | - |
32 | | -# \\ |
33 | | -print("Path: C:\Users\Baraa") |
34 | | -print("Path: C:\\Users\\Baraa") |
35 | | - |
36 | | -# \n New Line |
| 26 | +# --------------------------------------- |
| 27 | +# ESCAPE SEQUENCES |
| 28 | +# --------------------------------------- |
| 29 | + |
| 30 | +# \" and \' - Print quotes inside strings |
| 31 | + |
| 32 | +# print("Hi "Python"") #Invalid: Double quotes inside Double quotes |
| 33 | +print("Hi \"Python\"") # Fix1: Use escape character (backslash) |
| 34 | +print('Hi "Python"') # Fix2: Mix single and double quotes |
| 35 | +# print('Hi 'Python'') #Invalid: Single quote inside Single quotes |
| 36 | +print('Hi \'Python\'') # Fix1: Use escape character (backslash) |
| 37 | +print("Hi 'Python'") # Fix2: Mix single and double quotes |
| 38 | + |
| 39 | +# \\ - Backslash |
| 40 | +print("Path: C:\Users\Baraa") #Invalid |
| 41 | +print("Path: C:\\Users\\Baraa") |
| 42 | + |
| 43 | +# \n - New Line |
37 | 44 | print("Message1") |
38 | | -print() |
| 45 | +print() # Blank Line |
39 | 46 | print("Message2") |
40 | 47 |
|
41 | | -print("Message1\n") |
| 48 | +print("Message1\n") # Adds one new line |
42 | 49 | print("Message2") |
43 | 50 |
|
44 | | -print("Message1\n\n\nMessage2") |
| 51 | +print("Message1\n\n\nMessage2") # Adds three new lines |
| 52 | +print("Message1\nMessage2") # One new line between |
45 | 53 |
|
46 | | -print("Message1\nMessage2") |
47 | | - |
48 | | -# \t New Line |
| 54 | +# \t - Tab |
49 | 55 | print("Message1\tMessage2") |
50 | 56 |
|
| 57 | +# ----------------------------------------------- |
| 58 | +# CHALLENGE TIME |
| 59 | +# Recreate the following using ONLY ONE print() function: |
| 60 | +# Your learning Path: |
| 61 | +# -Python Basics |
| 62 | +# -Data Engineering |
| 63 | +# -AI |
| 64 | +# ----------------------------------------------- |
| 65 | + |
| 66 | +# Multi-line string with tabs |
51 | 67 | print("Your learning Path:\n\t-Python Basics\n\t-Data Engineering\n\t-AI") |
52 | 68 |
|
| 69 | +# Alternative multi-line string using triple quotes |
53 | 70 | print("""Your learning Path: |
54 | 71 | \t- Python Basics |
55 | 72 | \t- Data Engineering |
56 | 73 | \t- AI""") |
57 | 74 |
|
58 | | -# Why we need really PRINT() |
| 75 | +# --------------------------------------- |
| 76 | +# PRINT() | Real Use Case for PRINT() |
| 77 | +# --------------------------------------- |
| 78 | + |
59 | 79 | price_shirt = 25.00 |
60 | 80 | price_jeans = 45.50 |
61 | 81 |
|
|
0 commit comments