Basic python -4 (QNA)

Q1: What is the internal structure of Python strings?
A1: Python strings are sequences of Unicode characters, i.e., an ordered collection of characters. This means they maintain a left-to-right positional ordering among the characters. Each character in a string has a unique index, with the first character having an index of 0. Python strings are also immutable, which means once a string is defined, it cannot be changed.
Q2: Write a Python script that traverses through an input string and prints its characters in different lines two characters per line.
A2: Here is a simple Python script that accomplishes this:
                input_string = "Hello, World!"
                for i in range(0, len(input_string), 2):
                    print(input_string[i:i+2])
                
Q3: Discuss the utility and significance of Lists, briefly.
A3: Lists in Python are used to store multiple items in a single variable. They are one of the most versatile data types in Python, and are used extensively in data manipulation. Lists are mutable, meaning that their contents can be changed after creation. They can store different types of items, including numbers, strings, and other lists. They also support various methods for adding and removing items, sorting data, and more. In addition, they are essential for tasks like looping, and are often used in combination with loops to manipulate data and perform repetitive tasks.

Leave a Comment

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

Scroll to Top