1598583000

# Square Pattern Printing with Diagonals in C Programming Language

In this C pattern Programs tutorial you will learn to Print stars and numbers Hollow Square Shape with diagonals.

#c

1669003576

## Exploring Mutable and Immutable in Python

In this Python article, let's learn about Mutable and Immutable in Python.

## Mutable and Immutable in Python

Mutable is a fancy way of saying that the internal state of the object is changed/mutated. So, the simplest definition is: An object whose internal state can be changed is mutable. On the other hand, immutable doesn’t allow any change in the object once it has been created.

Both of these states are integral to Python data structure. If you want to become more knowledgeable in the entire Python Data Structure, take this free course which covers multiple data structures in Python including tuple data structure which is immutable. You will also receive a certificate on completion which is sure to add value to your portfolio.

### Mutable Definition

Mutable is when something is changeable or has the ability to change. In Python, ‘mutable’ is the ability of objects to change their values. These are often the objects that store a collection of data.

### Immutable Definition

Immutable is the when no change is possible over time. In Python, if the value of an object cannot be changed over time, then it is known as immutable. Once created, the value of these objects is permanent.

### List of Mutable and Immutable objects

Objects of built-in type that are mutable are:

• Lists
• Sets
• Dictionaries
• User-Defined Classes (It purely depends upon the user to define the characteristics)

Objects of built-in type that are immutable are:

• Numbers (Integer, Rational, Float, Decimal, Complex & Booleans)
• Strings
• Tuples
• Frozen Sets
• User-Defined Classes (It purely depends upon the user to define the characteristics)

Object mutability is one of the characteristics that makes Python a dynamically typed language. Though Mutable and Immutable in Python is a very basic concept, it can at times be a little confusing due to the intransitive nature of immutability.

## Objects in Python

In Python, everything is treated as an object. Every object has these three attributes:

• Identity – This refers to the address that the object refers to in the computer’s memory.
• Type – This refers to the kind of object that is created. For example- integer, list, string etc.
• Value – This refers to the value stored by the object. For example – List=[1,2,3] would hold the numbers 1,2 and 3

While ID and Type cannot be changed once it’s created, values can be changed for Mutable objects.

Check out this free python certificate course to get started with Python.

## Mutable Objects in Python

I believe, rather than diving deep into the theory aspects of mutable and immutable in Python, a simple code would be the best way to depict what it means in Python. Hence, let us discuss the below code step-by-step:

#Creating a list which contains name of Indian cities

``````cities = [‘Delhi’, ‘Mumbai’, ‘Kolkata’]
``````

# Printing the elements from the list cities, separated by a comma & space

``````for city in cities:
print(city, end=’, ’)

Output [1]: Delhi, Mumbai, Kolkata
``````

#Printing the location of the object created in the memory address in hexadecimal format

``````print(hex(id(cities)))

Output [2]: 0x1691d7de8c8
``````

#Adding a new city to the list cities

``````cities.append(‘Chennai’)
``````

#Printing the elements from the list cities, separated by a comma & space

``````for city in cities:
print(city, end=’, ’)

Output [3]: Delhi, Mumbai, Kolkata, Chennai
``````

#Printing the location of the object created in the memory address in hexadecimal format

``````print(hex(id(cities)))

Output [4]: 0x1691d7de8c8
``````

The above example shows us that we were able to change the internal state of the object ‘cities’ by adding one more city ‘Chennai’ to it, yet, the memory address of the object did not change. This confirms that we did not create a new object, rather, the same object was changed or mutated. Hence, we can say that the object which is a type of list with reference variable name ‘cities’ is a MUTABLE OBJECT.

Let us now discuss the term IMMUTABLE. Considering that we understood what mutable stands for, it is obvious that the definition of immutable will have ‘NOT’ included in it. Here is the simplest definition of immutable– An object whose internal state can NOT be changed is IMMUTABLE.

Again, if you try and concentrate on different error messages, you have encountered, thrown by the respective IDE; you use you would be able to identify the immutable objects in Python. For instance, consider the below code & associated error message with it, while trying to change the value of a Tuple at index 0.

#Creating a Tuple with variable name ‘foo’

``````foo = (1, 2)
``````

#Changing the index[0] value from 1 to 3

``````foo[0] = 3

TypeError: 'tuple' object does not support item assignment
``````

## Immutable Objects in Python

Once again, a simple code would be the best way to depict what immutable stands for. Hence, let us discuss the below code step-by-step:

#Creating a Tuple which contains English name of weekdays

``````weekdays = ‘Sunday’, ‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’, ‘Saturday’
``````

# Printing the elements of tuple weekdays

``````print(weekdays)

Output [1]:  (‘Sunday’, ‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’, ‘Saturday’)
``````

#Printing the location of the object created in the memory address in hexadecimal format

``````print(hex(id(weekdays)))

Output [2]: 0x1691cc35090
``````

#tuples are immutable, so you cannot add new elements, hence, using merge of tuples with the # + operator to add a new imaginary day in the tuple ‘weekdays’

``````weekdays  +=  ‘Pythonday’,
``````

#Printing the elements of tuple weekdays

``````print(weekdays)

Output [3]: (‘Sunday’, ‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’, ‘Saturday’, ‘Pythonday’)
``````

#Printing the location of the object created in the memory address in hexadecimal format

``````print(hex(id(weekdays)))

``````

This above example shows that we were able to use the same variable name that is referencing an object which is a type of tuple with seven elements in it. However, the ID or the memory location of the old & new tuple is not the same. We were not able to change the internal state of the object ‘weekdays’. The Python program manager created a new object in the memory address and the variable name ‘weekdays’ started referencing the new object with eight elements in it.  Hence, we can say that the object which is a type of tuple with reference variable name ‘weekdays’ is an IMMUTABLE OBJECT.

Where can you use mutable and immutable objects:

Mutable objects can be used where you want to allow for any updates. For example, you have a list of employee names in your organizations, and that needs to be updated every time a new member is hired. You can create a mutable list, and it can be updated easily.

Immutability offers a lot of useful applications to different sensitive tasks we do in a network centred environment where we allow for parallel processing. By creating immutable objects, you seal the values and ensure that no threads can invoke overwrite/update to your data. This is also useful in situations where you would like to write a piece of code that cannot be modified. For example, a debug code that attempts to find the value of an immutable object.

Watch outs:  Non transitive nature of Immutability:

OK! Now we do understand what mutable & immutable objects in Python are. Let’s go ahead and discuss the combination of these two and explore the possibilities. Let’s discuss, as to how will it behave if you have an immutable object which contains the mutable object(s)? Or vice versa? Let us again use a code to understand this behaviour–

#creating a tuple (immutable object) which contains 2 lists(mutable) as it’s elements

#The elements (lists) contains the name, age & gender

``````person = (['Ayaan', 5, 'Male'], ['Aaradhya', 8, 'Female'])
``````

#printing the tuple

``````print(person)

Output [1]: (['Ayaan', 5, 'Male'], ['Aaradhya', 8, 'Female'])

``````

#printing the location of the object created in the memory address in hexadecimal format

``````print(hex(id(person)))

Output [2]: 0x1691ef47f88
``````

#Changing the age for the 1st element. Selecting 1st element of tuple by using indexing [0] then 2nd element of the list by using indexing [1] and assigning a new value for age as 4

``````person[0][1] = 4
``````

#printing the updated tuple

``````print(person)

Output [3]: (['Ayaan', 4, 'Male'], ['Aaradhya', 8, 'Female'])
``````

#printing the location of the object created in the memory address in hexadecimal format

``````print(hex(id(person)))

Output [4]: 0x1691ef47f88
``````

In the above code, you can see that the object ‘person’ is immutable since it is a type of tuple. However, it has two lists as it’s elements, and we can change the state of lists (lists being mutable). So, here we did not change the object reference inside the Tuple, but the referenced object was mutated.

Same way, let’s explore how it will behave if you have a mutable object which contains an immutable object? Let us again use a code to understand the behaviour–

#creating a list (mutable object) which contains tuples(immutable) as it’s elements

``````list1 = [(1, 2, 3), (4, 5, 6)]
``````

#printing the list

``````print(list1)

Output [1]: [(1, 2, 3), (4, 5, 6)]

``````

#printing the location of the object created in the memory address in hexadecimal format

``````print(hex(id(list1)))

Output [2]: 0x1691d5b13c8	``````

#changing object reference at index 0

``````list1[0] = (7, 8, 9)
``````

#printing the list

``Output [3]: [(7, 8, 9), (4, 5, 6)]``

#printing the location of the object created in the memory address in hexadecimal format

``````print(hex(id(list1)))

Output [4]: 0x1691d5b13c8
``````

As an individual, it completely depends upon you and your requirements as to what kind of data structure you would like to create with a combination of mutable & immutable objects. I hope that this information will help you while deciding the type of object you would like to select going forward.

Before I end our discussion on IMMUTABILITY, allow me to use the word ‘CAVITE’ when we discuss the String and Integers. There is an exception, and you may see some surprising results while checking the truthiness for immutability. For instance:
#creating an object of integer type with value 10 and reference variable name ‘x’

x = 10

#printing the value of ‘x’

``````print(x)

Output [1]: 10
``````

#Printing the location of the object created in the memory address in hexadecimal format

``````print(hex(id(x)))

Output [2]: 0x538fb560

``````

#creating an object of integer type with value 10 and reference variable name ‘y’

``````y = 10
``````

#printing the value of ‘y’

``````print(y)

Output [3]: 10
``````

#Printing the location of the object created in the memory address in hexadecimal format

``````print(hex(id(y)))

Output [4]: 0x538fb560
``````

As per our discussion and understanding, so far, the memory address for x & y should have been different, since, 10 is an instance of Integer class which is immutable. However, as shown in the above code, it has the same memory address. This is not something that we expected. It seems that what we have understood and discussed, has an exception as well.

Quick checkPython Data Structures

### Immutability of Tuple

Tuples are immutable and hence cannot have any changes in them once they are created in Python. This is because they support the same sequence operations as strings. We all know that strings are immutable. The index operator will select an element from a tuple just like in a string. Hence, they are immutable.

## Exceptions in immutability

Like all, there are exceptions in the immutability in python too. Not all immutable objects are really mutable. This will lead to a lot of doubts in your mind. Let us just take an example to understand this.

Consider a tuple ‘tup’.

Now, if we consider tuple tup = (‘GreatLearning’,[4,3,1,2]) ;

We see that the tuple has elements of different data types. The first element here is a string which as we all know is immutable in nature. The second element is a list which we all know is mutable. Now, we all know that the tuple itself is an immutable data type. It cannot change its contents. But, the list inside it can change its contents. So, the value of the Immutable objects cannot be changed but its constituent objects can. change its value.

## FAQs

#### 2. What are the mutable and immutable data types in Python?

• Some mutable data types in Python are:

list, dictionary, set, user-defined classes.

• Some immutable data types are:

int, float, decimal, bool, string, tuple, range.

#### 3. Are lists mutable in Python?

Lists in Python are mutable data types as the elements of the list can be modified, individual elements can be replaced, and the order of elements can be changed even after the list has been created.
(Examples related to lists have been discussed earlier in this blog.)

#### 4. Why are tuples called immutable types?

Tuple and list data structures are very similar, but one big difference between the data types is that lists are mutable, whereas tuples are immutable. The reason for the tuple’s immutability is that once the elements are added to the tuple and the tuple has been created; it remains unchanged.

A programmer would always prefer building a code that can be reused instead of making the whole data object again. Still, even though tuples are immutable, like lists, they can contain any Python object, including mutable objects.

#### 5. Are sets mutable in Python?

A set is an iterable unordered collection of data type which can be used to perform mathematical operations (like union, intersection, difference etc.). Every element in a set is unique and immutable, i.e. no duplicate values should be there, and the values can’t be changed. However, we can add or remove items from the set as the set itself is mutable.

#### 6. Are strings mutable in Python?

Strings are not mutable in Python. Strings are a immutable data types which means that its value cannot be updated.

Join Great Learning Academy’s free online courses and upgrade your skills today.

Original article source at: https://www.mygreatlearning.com

1672928580

## How to Bash Read Command

Bash has no built-in function to take the user’s input from the terminal. The read command of Bash is used to take the user’s input from the terminal. This command has different options to take an input from the user in different ways. Multiple inputs can be taken using the single read command. Different ways of using this command in the Bash script are described in this tutorial.

## Syntax

read [options] [var1, var2, var3…]

The read command can be used without any argument or option. Many types of options can be used with this command to take the input of the particular data type. It can take more input from the user by defining the multiple variables with this command.

## Some Useful Options of the Read Command

Some options of the read command require an additional parameter to use. The most commonly used options of the read command are mentioned in the following:

## Different Examples of the Read Command

The uses of read command with different options are shown in this part of this tutorial.

Example 1: Using Read Command without Any Option and variable

Create a Bash file with the following script that takes the input from the terminal using the read command without any option and variable. If no variable is used with the read command, the input value is stored in the \$REPLY variable. The value of this variable is printed later after taking the input.

``````#!/bin/bash
#Print the prompt message
echo "Enter your favorite color: "
#Take the input
#Print the input value

Output:

The following output appears if the “Blue” value is taken as an input:

Example 2: Using Read Command with a Variable

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable. The method of taking the single or multiple variables using a read command is shown in this example. The values of all variables are printed later.

``````#!/bin/bash
#Print the prompt message
echo "Enter the product name: "
#Take the input with a single variable

#Print the prompt message
echo "Enter the color variations of the product: "
#Take three input values in three variables
read color1 color2 color3

#Print the input value
echo "The product name is \$item."
#Print the input values
echo "Available colors are \$color1, \$color2, and \$color3."``````

Output:

The following output appears after taking a single input first and three inputs later:

Example 3: Using Read Command with -p Option

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable and the -p option. The input value is printed later.

``````#!/bin/bash
#Take the input with the prompt message
read -p "Enter the book name: " book
#Print the input value
echo "Book name: \$book"``````

Output:

The following output appears after taking the input:

Example 4: Using Read Command with -s Option

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable and the -s option. The input value of the password will not be displayed for the -s option. The input values are checked later for authentication. A success or failure message is also printed.

``````#!/bin/bash
#Take the input with the prompt message
read -p "Enter your email: " email
#Take the secret input with the prompt message

echo ""

#Check the email and password for authentication
if [[ \$email == "admin@example.com" && \$password == "secret" ]]
then
#Print the success message
echo "Authenticated."
else
#Print the failure message
echo "Not authenticated."
fi``````

Output:

The following output appears after taking the valid and invalid input values:

Example 5: Using Read Command with -a Option

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable and the -a option. The array values are printed later after taking the input values from the terminal.

``````#!/bin/bash
echo "Enter the country names: "
#Take multiple inputs using an array

echo "Country names are:"
#Read the array values
for country in \${countries[@]}
do
echo \$country
done``````

Output:

The following output appears after taking the array values:

Example 6: Using Read Command with -n Option

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable and the -n option.

``````#!/bin/bash
#Print the prompt message
echo "Enter the product code: "
#Take the input of five characters
read -n 5 code
echo ""
#Print the input value
echo "The product code is \$code"``````

Output:

The following output appears if the “78342” value is taken as input:

Example 7: Using Read Command with -t Option

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable and the -t option.

``````#!/bin/bash
#Print the prompt message
echo -n "Write the result of 10-6: "
#Take the input of five characters

#Check the input value
if [[ \$answer == "4" ]]
then
else
fi``````

Output:

The following output appears after taking the correct and incorrect input values:

## Conclusion

The uses of some useful options of the read command are explained in this tutorial using multiple examples to know the basic uses of the read command.

Original article source at: https://linuxhint.com/

1594464365

## Advantage of C Language Certification Online Training in 2020

C language is a procedural programming language. C language is the general purpose and object oriented programming language. C language is mainly used for developing different types of operating systems and other programming languages. C language is basically run in hardware and operating systems. C language is used many software applications such as internet browser, MYSQL and Microsoft Office.
**
Advantage of doing C Language Training in 2020 are:**

1. Popular Programming language: The main Advantage of doing C language training in 2020 is popular programming language. C programming language is used and applied worldwide. C language is adaptable and flexible in nature. C language is important for different programmers. The basic languages that are used in C language is Java, C++, PHP, Python, Perl, JavaScript, Rust and C- shell.

2. Basic language of all advanced languages: The another main Advantage of doing C language training in 2020 is basic language of all advanced languages. C language is an object oriented language. For learning, other languages, you have to master in C language.

3. Understand the computer theories: The another main Advantage of doing C language training in 2020 is understand the computer theories. The theories such as Computer Networks, Computer Architecture and Operating Systems are based on C programming language.

4. Fast in execution time: The another main Advantage of doing C language training in 2020 is fast in execution time. C language is to requires small run time and fast in execution time. The programs are written in C language are faster than the other programming language.

5. Used by long term: The another main Advantage of doing C language training in 2020 is used by long term. The C language is not learning in the short span of time. It takes time and energy for becoming career in C language. C language is the only language that used by decades of time. C language is that exists for the longest period of time in computer programming history.

6. Rich Function Library: The another main Advantage of doing C language training in 2020 is rich function library. C language has rich function of libraries as compared to other programming languages. The libraries help to build the analytical skills.

7. Great degree of portability: The another main Advantage of doing C language training in 2020 is great degree of portability. C is a portable assemble language. It has a great degree of portability as compilers and interpreters of other programming languages are implemented in C language.
The demand of C language is high in IT sector and increasing rapidly.

C Language Online Training is for individuals and professionals.
C Language Online Training helps to develop an application, build operating systems, games and applications, work on the accessibility of files and memory and many more.

C Language Online Course is providing the depth knowledge of functional and logical part, develop an application, work on memory management, understanding of line arguments, compiling, running and debugging of C programs.

Is C Language Training Worth Learning for You! and is providing the basic understanding of create C applications, apply the real time programming, write high quality code, computer programming, C functions, variables, datatypes, operators, loops, statements, groups, arrays, strings, etc.

The companies which are using C language are Amazon, Martin, Apple, Samsung, Google, Oracle, Nokia, IBM, Intel, Novell, Microsoft, Facebook, Bloomberg, VM Ware, etc.
C language is used in different domains like banking, IT, Insurance, Education, Gaming, Networking, Firmware, Telecommunication, Graphics, Management, Embedded, Application Development, Driver level Development, Banking, etc.

The job opportunities after completing the C Language Online certificationAre Data Scientists, Back End Developer, Embedded Developer, C Analyst, Software Developer, Junior Programmer, Database Developer, Embedded Engineer, Programming Architect, Game Programmer, Quality Analyst, Senior Programmer, Full Stack Developer, DevOps Specialist, Front End Web Developer, App Developer, Java Software Engineer, Software Developer and many more.

#c language online training #c language online course #c language certification online #c language certification #c language certification course #c language certification training

1599550659

## Benefits Of C Language Over Other Programming Languages

C may be a middle-level programing language developed by Dennis Ritchie during the first 1970s while performing at AT&T Bell Labs within the USA. the target of its development was within the context of the re-design of the UNIX OS to enable it to be used on multiple computers.

Earlier the language B was now used for improving the UNIX. Being an application-oriented language, B allowed a much faster production of code than in programming language. Still, B suffered from drawbacks because it didn’t understand data-types and didn’t provide the utilization of “structures”.

These drawbacks became the drive for Ritchie for the development of a replacement programing language called C. He kept most of the language B’s syntax and added data-types and lots of other required changes. Eventually, C was developed during 1971-73, containing both high-level functionality and therefore the detailed features required to program an OS. Hence, many of the UNIX components including the UNIX kernel itself were eventually rewritten in C.

Benefits of C language

As a middle-level language, C combines the features of both high-level and low-level languages. It is often used for low-level programmings, like scripting for it also supports functions of high-level C programming languages, like scripting for software applications, etc.
C may be a structured programing language that allows a posh program to be broken into simpler programs called functions. It also allows free movement of knowledge across these functions.

Various features of C including direct access to machine level hardware APIs, the presence of C compilers, deterministic resource use, and dynamic memory allocation make C language an optimum choice for scripting applications and drivers of embedded systems.

C language is case-sensitive which suggests lowercase and uppercase letters are treated differently.
C is very portable and is employed for scripting system applications which form a serious a part of Windows, UNIX, and Linux OS.

C may be a general-purpose programing language and may efficiently work on enterprise applications, games, graphics, and applications requiring calculations, etc.
C language features a rich library that provides a variety of built-in functions. It also offers dynamic memory allocation.

C implements algorithms and data structures swiftly, facilitating faster computations in programs. This has enabled the utilization of C in applications requiring higher degrees of calculations like MATLAB and Mathematica.

Riding on these advantages, C became dominant and spread quickly beyond Bell Labs replacing many well-known languages of that point, like ALGOL, B, PL/I, FORTRAN, etc. C language has become available on a really wide selection of platforms, from embedded microcontrollers to supercomputers.

#c language online training #c language training #c language course #c language online course #c language certification course

1607339640

## C programming for Beginners | Learn C Programming | C Language

C Language is an evergreen language and is used widely across different industries, This C programming is a must for students and working professionals to become a great Software Engineer especially when they are working in Software Development Domain. Great Learning brings you this live session on “Introduction to C”. In this live session, we will be covering major concepts in C Programming such as Different Variables, Different Data Types that are being used, its Operators, Flow control statements, Structure, and lot more.

#c #programming #developer #c-programming #c-language