DEV Community

Cover image for Day 17: Unveiling the Magic of INTRODUCTION in Java, C++, Python, and Kotlin! πŸš€
Nitin-bhatt46
Nitin-bhatt46

Posted on

Day 17: Unveiling the Magic of INTRODUCTION in Java, C++, Python, and Kotlin! πŸš€

DAY - 17

Today’s Learning :-

For more Tech content Join us on linkedin click here

All the code snippets in this journey are available on my GitHub repository. πŸ“‚ Feel free to explore and collaborate: Git Repository

Java and Cpp Question.

1: Take 20 elements from user input and find its sum with the help of an array.
( AddTwentyArray)

2: Calculate the average of elements in an array of size 18.
(AverageOfArray)

3: Find the index of a specific element in an array, if the element is nor present, print -1. Ask the size of the array from the user and then implement it.

( IndexFinder )

In Python, a tuple is a built-in data structure similar to a list, but with some key differences. Here's an explanation of tuples:
Immutable: Unlike lists, tuples are immutable, meaning that once they are created, their elements cannot be changed or modified. You cannot add, remove, or modify elements in a tuple after it is created.
Ordered: Similar to lists, tuples maintain the order of elements as they are added. The order in which elements are inserted into a tuple is preserved when accessing or iterating over the tuple.

Dynamic Size: Like lists, tuples can dynamically resize themselves as needed. You can add or remove elements from a tuple without specifying its size beforehand.

Accessing Elements: Elements in a tuple are accessed using zero-based indexing, just like in lists. You can access individual elements by their index, and you can also slice tuples to retrieve a subset of elements.

Immutable Elements: While the tuple itself is immutable, its elements may be mutable if they are mutable data types (e.g., lists). However, you cannot change the reference to the element within the tuple.

Tuples are commonly used when you want to represent a collection of items that should not change over time, such as coordinates, database records, or function return values with multiple components.

Here's an example of creating and using a tuple in Python:

Creating a tuple

Accessing elements

Slicing

Immutable nature

This will raise an error:
Eg :- my_tuple[0] = 10

Length of tuple

Tuples are useful for representing fixed collections of data where immutability is desired. They offer a lightweight and efficient way to work with ordered sequences of values in Python.
Feel free to reshare this post to enhance awareness and understanding of these fundamental concepts.
Code snippets are in the Git repository.

πŸ™ Thank you all for your time and support! πŸ™

Top comments (0)