Input and output Basics In Python

This topic discusses input and output basics in Python topic based on string concatenation, concatenation errors, string Repetition, length of string, and taking input from the user string.


  INPUT AND OUTPUT BASICS

 


        topic1: working with strings and string concatenation

  • String Concatenation:
    Joining strings together is called string concatenation
    Example code 1:

    a="Hello"+" "+"World" 
    print(a)
    
    
    


    Output:

    Hello World
  • String Concatenation with Number:
    Joining strings together is called string concatenation with a number using double code notation.Example code 2:

    num1="1"
    num2="2" 
    print(num1+num2)
    Output:   
    12

    topic2: working with string Concatenation Error

             String Concatenation Error:
               String Concatenation is possible only with strings.

    Example code 1:

    a="*"+10 
    print(a)
    output: 
    ERROR!
    Traceback (most recent call last):
    File "<main.py>", line 3
    a="*"+10 print(a)
    ^^^^^
    SyntaxError: invalid syntax

    topic3:  Working with string repetition

    String repetition: String repetition is used for a string in a word multiple times. The * operator is used for repeating strings as often as required.


    Example code 1:

    name=" python "*10
    print(name)
    output: 
     python python python python python python python python python  
    
    

    Example code 2:

    a="name" 
    b=("* "*3)+ a +("* "*3)
    print(b)
    output: 
    * * * name* * *

    topic4:  Working  with a length of String

    Length of string:  in this method, we can check the length of the string len()returns the number of characters in a given string.   

Example code 2:  

name="rammohansai" 
print(len(name))
output: 
11

topic4:  Working  with string taking input from the user
Input from the user:
string or number-taking form the user to use the method input () allows flexibility to take the input from the user. 

Example code 1:

A=input()
B=input() 
print(A+B)
OUTPUT:
RAM 
MOHAN
RAM MOHAN

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top