Created by Bhawani Shankar

Contact me via email =>[email protected]

Day 1:

Topics to be covered => Printing , Commenting , Debugging , String Manipulation and Variables

// First python program 
# print("Shree ganesh")
print("Day 1 - Python Print Function")
print("print('What to print')") 
 # Both inside string and outside string will have different inverted comma

image.png

Take care of space

image.png

String manipulation :

  1. Creating Strings: In Python, you can create strings using single quotes or double quotes.

    greeting = 'Hello'
    name = "Alice"
    
    
  2. Concatenation: Joining strings together is called concatenation. You can use the '+' operator.

    full_greeting = greeting + ' ' + name
    print(full_greeting)  # Output: Hello Alice
    
    
  3. String Length: To find the length of a string, use the len() function.

    print(len(name))  # Output: 5
    
    
  4. Accessing Characters: You can access individual characters in a string using indexing. Remember, indexing starts at 0.

    first_letter = name[0]
    print(first_letter)  # Output: A
    
    
  5. Slicing: You can extract parts of a string using slicing.

    print(name[1:3])  # Output: li
    
    
  6. String Methods: Python provides many built-in methods for string manipulation. Here are a few common ones:

    a. Upper and Lower case:

    print(name.upper())  # Output: ALICE
    print(name.lower())  # Output: alice
    
    

    b. Replace:

    sentence = "The quick brown fox"
    new_sentence = sentence.replace("fox", "dog")
    print(new_sentence)  # Output: The quick brown dog
    
    

    c. Split:

    words = sentence.split()
    print(words)  # Output: ['The', 'quick', 'brown', 'fox']
    
    

    d. Join:

    joined = "-".join(words)  # join them using -
    # opposite of split() which breaks a string into parts, join() combines a list of strings into a single string.
    print(joined)  # Output: The-quick-brown-fox
    
    
  7. Formatting: You can format strings using f-strings (available in Python 3.6+):

    age = 25
    #You start the string with the letter 'f' or 'F' before the opening quotation mark.
    #Inside the string, you can put expressions in curly braces {}.
    #Python will evaluate these expressions and convert them to strings.
    formatted = f"My name is {name} and I am {age} years old"  # It works like teplate literal in javascript
    print(formatted)  # Output: My name is Alice and I am 25 years old
    
    

The input() function in Python is a built-in function used to get user input from the command line.

name = input("What is your name? ")
print(f"Hello, {name}!")