Inputs and Outputs Basics
Cheat Sheet Inputs and Outputs Basics Take Input From User input() allows flexibility to take the input from the user. Reads a line of input as a string. Code: username = input() print(username) Input Ajay Output Ajay Working with Strings String Concatenation Joining strings together is called string concatenation. Code a = "Hello" + " " + "World" print(a) Output: Hello World Concatenation Errors String Concatenation is possible only with strings. Code: a = "*" + 10 print(a) Output: File "main.py", line 1 a = "*" + 10 ^ TypeError: can only concatenate str (not "int") to str String Repetition * operator is used for repeating strings any number of times as required. Code: a = "*" * 10 print(a) Output: ********** Code: s = "Python" s = ("* " * 3) + s + (" *" * 3) print(s) Output: * * * Python * * * Length of String len() returns the number of characters in a given string. Code: ...