Wednesday, 24 November 2021

Sequence DataType Part - III [Slicing]



Sequence data operations: Slicing


•   The slice() constructor creates a slice object representing the set of indices specified by 
range(start, stop, step)
•   Syntax: slice(stop), slice(start, stop, step)
•   If a single parameter is passed, start and step are set to None

So, let us get started with slicing. So, the slice object is used to slice a given sequence and the
sequence can be string the sequence can be strings tuples, bytes, list or range or any object which
supports sequence protocol. And the slice object represents the indices specified by the range
function given the start stop and the step value. And the syntax of the slice operation the syntax
for the slice object is given here and the syntax for the slice function is given here.

So, you can either use slice of stop or you can use slice of start stop and step. So, basically the
slice function takes in three arguments which have the same meaning in both the constructs. So,
the first one is start which is a starting integer value where the string which is an integer value
which is an integer value which represents the starting from where the slicing of the objects.






So, the first argument is start. So, that is the starting integer where the slicing of the object starts
the next one is top that is an integer until which the slicing takes place. So the slicing stops at the
index n minus 1 or the minus 1.. So, for example I have given the second argument as 4 it means
that is the stop value. So, it is going to give me the sequence of values still 3. So, next one is step
an integer value which determines the increment between each index for slicing.

So, for example if you are giving 2, so, you will fetch the, so, you will be getting the values in
the step size 2. So, by default if you do not give anything it is going to take it as 1 as the
increment value but if you are providing any value then it is going to consider that as the
increment value.


String Slicing 






So, let us just get started with the example on string. So, we have already
created the string called strsample which has a string called learning. So, now my objective is to
get the substring from a given string strsample from the given string learn from the given string
learning.

So, we can use the slice object to do that. So, on strsample I am using the slice of I am using the
slice function inside the square brackets then inside the slice function I am just giving three
values one for start stop and the step value. So, here the output I have already printed that is er
which is e and r from learning. So, basically we have got that by specifying the starting index as
one. So, actually the slicing started from e and it will actually end at the index 4 then it is 2 3 and
4.

So, n will have the index 4 but actually it is going to give you till n minus 1 right. So, it will stop
at r and since I have given the increment value as 2 it is not going to give you all the sequence of
sequence of strings from e as it is not going to give you the sequence of strings as e a r rather it is
going to give you the sequence in terms of incrementing the strings by two. So, it is just going to
give you as a r alone.

So, it is just going to give you the output as e r alone. So, this is how the slicing operator. So, this
is how we use the slice function in order to slice the given sequence of elements or given
sequence of substrings from the given string or the any sequence object. And the other method is
the other method for slicing the elements or the substrings from a given object is using the square
bracket. You do not have to use the slice function inside it you can either use the slice function or

the colon operator.

Here I am using just a colon inside the square bracket. So, that it gives me all the substrings from
a string learning that is learning. So, just by giving just by just placing colon inside the square
brackets fetches me the learning that is the complete set of strings from the main string that is
strsample. So, this is how we perform the slicing on the string sequence data. So, basically we
use slicing whenever we want to perform any operations on a particular set of elements on your
string or on your any or it can be applied on any sequence data.

So, all the values from a list will not get modified based on your calculation or based on your
operation only the particular set of elements or substrings will be modified based on the
operations that you are performing on it.


List Slicing




it. Similarly we can perform the slicing operations in other
in any other sequence data for example the next example to illustrate you is on list. So, lists
basically have a default bit of functionality when slicing.

So, here let us just print what is there under the list sample so these are the values these are the
elements that is there under the lstsample 1 2 a sam and 2. So, now I am going to perform slicing
on the list sample. So, basically if there is no volume before the first colon for example like this I
have not given any value before the first colon and I have given value after the colon in that case
it needs to start at the beginning index of the list.

It means to start the slicing at the beginning index of the list. So, let us just see what happens
when we use colon 3. So, the output is given here. So, this the slicing started from the index 1.
So, the slicing started from the beginning of the list that is from 1 itself and the next value is the
stop value. So, 0 1 2 3 it is going to give you the sub elements from the list till or before sam. So,
we have got the output as 1 2 and a.

Since the index the since the stop index is at 3 it is just going to give you a value it is just going
to give you a sequence of elements or sequence of sub elements from your main list which is just
before the third index that is 1 2 and a. The other thing to note here if you have not provided a
value after the first colon like this then it means to go all the way to the end of the list starting

from the index 2. So, I am just saying to slice starting from the index 2 and to go all the way to
the end of a list and this basically saves this time.

So, that we do not have to manually specify length of a which basically. So, this saves us time.
So, that we do not have to manually specify length of len of lstsample in order to specify that is
the end of a list or that is to specify the that is to specify or to check how many elements are
there in a list. So, in order to get rid of that you can just use a colon after the you can you do not
have to specify anything after the first column. So, that it automatically takes all the sub elements
till the end of your list. So, this is how we perform the slicing operation on a list.

So, here if you have noted down I have not used the slice function rather I have just used the
colon operator to slice the sub elements from the list by just separating by just giving the start
stop and the step value in terms of using colon operator. And if you can recall here whatever
order that you are giving here inside the slice option inside the slice function the same applies
here but instead of using slice function I have just used the square bracket.

And if I give 2 colon 3 colon 1 then it means that starting while the starting index is 2 and the
ending index is 3 and the increment value is 1 but you can as well specify without even giving
any value just to denote that I need all the values from 2 and I need all the values till 3.
(Refer Slide Time: 09:54)

For example this is the start value and the stop value let us check what is the output? So, the
slicing operation is being done from the index 2 of the list that is 0 1 2 from a until 4 3 and 4 and
it is not going to consider the 4 as the index but it just considered till n minus 1. So, that will be
3. So, it is going to give you a and sam as the output. So, I hope this is clear. So, let us move on
to performing the slicing on the other sequential data.

Dictionary Slicing



So, we have also created a dictionary sample right so let us just perform slicing on it but it gives
you an error saying type error and hashable type that is slice. So, if you can recall the python
dictionary object provides a key value indexing facility and the values in the dictionary are
indexed by keys and they are not held in any order in that case we will not be able to perform
slicing because it requires the index to slice the given sequence of values or given sequence of
elements.

To slice the sequence of values or sequence of keys from your dictionary, so, slice. So, we
cannot perform slicing on a dictionary because it is a non it is a container for non it is a container
for holding non sequential data.


Set Slicing




So, in that case we will not be able to apply that onto a set as well. So, let us just see what happens when we apply that onto a set. So, it also throws an error
saying set object is not subscriptable.

As we know that set is also a container to hold non-sequential data. So, all the elements inside
the set are not indexed or not indexed by any indices rather they are not they are not held in any
order. So, we cannot perform the slicing operation on a set also because even set is also a
container for holding the non-sequential data in that case all the elements inside the set will not
have any index for index corresponding to each element. So, we can perform the slicing in index
as well.




Join us: https://t.me/jupyter_python

Tuesday, 23 November 2021

Sequence DataType Part - II [Indexing]

Sequence data operations: Indexing

Indexing just means accessing elements. To access elements, the square brackets can be used. There 
are many methods to access elements in python.

index() method finds the first occurrence of the specified value and returns its position 

Syntax: object.index(sub[, start[, end]] ), object[index]

•   Index of the element is used to access an element from ordered sequences
•   The index starts from 0
•   Negative indexing is used to access elements from the end of a list
•   In negative indexing, the last element of a list has the index -1

String Indexing

The first let us look at what string data type is. A string is a sequence of one or more characters, for example, it can contain letters, numbers and symbols and that can be either a constant or variable. And strings are basically a mutable sequence in Python. So, to create a string we can close a sequence of characters inside single, double or triple quotes. Let us see an example on creating string. Create string includes A sequence of characters inside single, double or triple quotes. I am creating the string called strsample and it has a sequence of characters which describes the word learning and storing that on two variable called strsample. So that becomes a string. So we can print out strings by simply calling the print function. So when we print the string strsample will be getting an output call learning. So the strsample is now a string.





List Indexing

So let us move to the next sequence data that is called list.So here I am just going to illustrate you the indexing part using the list sequenced data. So syntax
is given here you can use the list name and you can use the index function. And inside the
function we can just give the element for which you want to find the position. So I have already
created a list call list lstsample which has few elements to it. It has both numbers and strings and
to find the index of the element sam I can use the index method.

Inside the method I can just give the element sam. So that gives me an output three because
index corresponds to Sam is 3. The index corresponds to 1 is 0 and the index corresponds 2 is 1

and index corresponds to a is 2 and index corresponds to sam is 3. But if you are going to find
the element corresponding to a given index, then you can get that using square brackets. So let us
just try that I am using lissample of two inside the square bracket.

So it is going to give me an element which response to the index 2 which is nothing but a here.
Similarly you can access any elements from the end of a list as well using the negative indexing.
So if I give lissample of -1 is going to give me the last element of the list lissample. So which is
nothing but 2.







Array Indexing 

Similarly we can perform the indexing on an array. So we have already seen how to create an
array. So let us just use the same example. So I print out the values of array. The array sample
has values 1, 2, 3 and 4. So, here I just have an example to show you how you can perform the
negative index on this array. I am accessing the third last element of the array so it is going to
give me the value 2 which is nothing but the third last element of the array.

And similarly we can perform that on a tuple. So you can use the index method to find the
position of the given elements. So let me just use py so the index of py is 5. So here I am just
trying to find the element which responds to the second index which is 3 here. So, let us see how
the indexing works in set.


So we were already created a set sample which has example 24, 87.5 data 24 and data as
element to it. I am trying to use an index call 4 which gives me an error saying set object is not
subscriptable which means that you cannot perform the indexing operation set. As we know that
set is container to hold non sequential data. You will not be able to access the elements inside the
set using indexing.




Dictionary Indexing

So next we are going to see how we can perform indexing on a dictionary. So, Python dictionary
object provides a key-value pair facility. So the values in the dictionary are indexed by keys and
they are not held in any order. So, if you want to access the values from the dictionary then you
can access them by using their keys. So we have dictionary called dict sample which we have
already created which has keys as one second 3 and 4 and it also has a key value corresponding
to it.

For example first, 2, 3 and 4 so now let us see what happens when you are trying to access an
element using a index I am using index say for example that is 2 it gives you the key error that is
2 as we know that values in a dictionary or indexed by keys. So you will be able to access them
using keys not using the index. So now I am using key inside my square braces. So I am going to
get a value corresponding to the key that is 1.

So the value corresponding to the key one is first and as we know that he can may be a string or
integer value. So key can either have string as well as a integer. So here I have a key called
second so I will be able to access the value corresponding to the key second. So I am getting
output as 2. So, the value corresponding to key second is 2.







Range Indexing



So the last one example which is the last one is to illustrate the indexing using range. So we have
already created range sample which contains a value is 1, 5 and 9. So, you should be using an
appropriate value which is already there in your range if you are trying to give you a value which
is not in the range then it is going to throw you a value error. We are trying to check the index
corresponding to the value zero.

But in our case the range sample does not have the value 0 at all because it has only the values 1,
5, 9 in that case it throws a value error. So it says zero is not in range. But if you are trying to
find the position of the given element that is 9 here you will be able to do that because we
already have a range value that is 9 and it gives you the position of that particular element that is
2 and we can also get the elements given the index.

So, given the index as one, so it give the output as 5 because the index corresponding to the
value one is zero and the index corresponding to the value 5 is 1. But if you are trying to give the
index which is out of range then it is also going to throw you an error saying index error because
you have an error in the given index that is why the error says it is index error and saying range

object index out of range. Because you do not have any element corresponding to the index 9
that is, why the error says index error.






















Join us: https://t.me/jupyter_python

Monday, 22 November 2021

Sequence DataType Part - I

Sequence data type


•   Strings - Sequence of characters - " (or) '




•   Tuples - Sequence of compound data - ()




•   Lists - Sequence of multi-data type objects - []




•   Arrays - Sequence of constrained list of objects (all objects of same datatype) using array module from array package




•   Dictionary- Sequence of key-value pairs - {}




•   Sets - Sequence of unordered collection of unique data





•   Range - Used for looping - using built-in range( )










Join us: https://t.me/jupyter_python

Sunday, 21 November 2021

Introduction to java | Java tutorials | History of Java | JDK | JVM | JRE | Different Types of Java Platforms

What is Java?

Java is a class-based object-oriented programming language.

It is the most popular programming language.

Building web and desktop applications.

The language of choice for Android programming.

 

Java Platform

Java Platform is a collection of programs that help programmers to develop and run Java programming applications efficiently.

It includes an execution engine, a compiler, and a set of libraries in it.

It is a set of computer software and specifications.

James Gosling developed the Java platform at Sun Microsystems, and the Oracle Corporation later acquired it.

Java is a multi-platform, object-oriented, and network-centric language. It is among the most used programming language. Java is also used as a computing platform.

What is Java used for?

It is used for developing Android Apps

Helps you to create Enterprise Software

Wide range of Mobile java Applications

Use for big data Analytics.

Java Programming of Hardware devices

Used for Server-Side Technologies like Apache, JBoss, GlassFish, etc.

 

History of Java Programming Language

The Java language was initially called OAK.

it was developed for handling portable devices and set-top boxes.

In 1995, Sun changed the name to “Java” and modified the language to take advantage of the burgeoning www (World Wide Web) development business.

Later, in 2009, Oracle Corporation acquired Sun Microsystems and took ownership of three key Sun software assets: Java, MySQL, and Solaris.

Java Versions

JDK Alpha and Beta

   1995

JDK 1.0

23rd Jan 1996

JAVA SE 15

           15th Sep 2020 (latest Java Version)

 

 

Java Features

  • It is one of the easy-to-use programming languages to learn.
  • Write code once and run it on almost any computing platform.
  • Java is platform-independent. Some programs developed in one machine can be executed in another machine.
  • It is designed for building object-oriented applications.
  • It is a multi threaded language with automatic memory management.
  • It is created for the distributed environment of the Internet.
  • Facilitates distributed computing as its network-centric.

Java Development kit (JDK)

 

JDK is a software development environment used for making applets and Java applications.

Java developers can use it on Windows, macOS, Solaris, and Linux.

It is possible to install more than one JDK version on the same computer.

Why use JDK?

 

· JDK contains tools required to write Java programs and JRE to execute them.

· It includes a compiler, Java application launcher, Applet viewer, etc.

· Compiler converts code written in Java into byte code.

Java Virtual Machine (JVM):

 

Java Virtual Machine (JVM) is an engine that provides a runtime environment to drive the Java Code or applications.

It converts Java bytecode into machine language.

Why use JVM?

  • JVM provides a platform-independent way of executing Java source code.
  • It has numerous libraries, tools, and frameworks.
  • Once you run a Java program, you can run on any platform and save lots of time.
  • JVM comes with JIT (Just-in-Time) compiler that converts Java source code into low-level machine language. Hence, it runs faster than a regular application.

Java Runtime Environment (JRE)

JRE is a piece of software that is designed to run other software.

It contains the class libraries, loader class, and JVM.

If you are not a programmer, you don’t need to install JDK, but just JRE to run Java programs.

Why use JRE (Java Runtime Environment)

  • JRE contains class libraries, JVM, and other supporting files. It does not include any tool for Java development like a debugger, compiler, etc.
  • It uses important package classes like math, swing, util, lang, awt, and runtime libraries.
  • If you have to run Java applets, then JRE must be installed in your system.

 

Different Types of Java Platforms

1.       Java Platform, Standard Edition (Java SE):

Java SE’s API offers the Java programming language’s core functionality.

It defines all the basis of type and object to high-level classes.

It is used for networking, security, database access, graphical user interface (GUI) development, and XML parsing.

 

2.       Java Platform, Enterprise Edition (Java EE):

The Java EE platform offers an API and runtime environment for developing and running highly scalable, large-scale, multi-tiered, reliable, and secure network applications.

 

3.       Java Programming Language Platform, Micro Edition (Java ME):

The Java ME platform offers an API and a small-footprint virtual machine running Java programming language applications on small devices, like mobile phones.

 

API :  Application programming interface

An API is a set of programming code that enables data transmission between one software product and another. It also contains the terms of this data exchange.

 

4.       Java FX: 

JavaFX is a platform for developing rich internet applications using a lightweight user-interface API. It user hardware-accelerated graphics and media engines that help Java take advantage of higher-performance clients and a modern look-and-feel and high-level APIs for connecting to networked data sources.

First Program :

 

Class abc {

Public static void main(String args[]){

System.out.println(“Hello World”);

}

}

 


Types of Operators in Python

Assignment Operator 

Assignment operators are used to assign values to variables.

 There are 5 types of assignments operators 




Relational or Comparison Operator


Relational operator tests numerical equalities and inequalities between two operands and returns a boolean value

All operators have same precedence

So now, we will create two variables x and y with values 5 and 7 respectively and test the operators on them.




       
Logical Operators

Logical Operators are used when operands are conditional statements and it returns boolean value.

In python, logical operators are designed to work with scalars or boolean values.




 Join us: https://t.me/jupyter_python

Operators in Python


Operators and Operands

Operators are special symbol that help in carrying out an assignment operation or arithmetic or logical computation

Value that the operator operates on is called operand

Example:

2 + 3 = 5 

Here, plus sign ("+") is the Operator and "2","3" are the Operands.

Arithmetic Operators 

Used to perform mathematical operations between two operands.

So now, we will create two variables as a = 10 and b = 5 and perform some basic operations on them.




Hierarchy of arithmetic operators


Example:

Popular Posts

Categories

100 Python Programs for Beginner (49) AI (34) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (173) C (77) C# (12) C++ (82) Course (67) Coursera (226) Cybersecurity (24) data management (11) Data Science (128) Data Strucures (8) Deep Learning (20) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (34) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (59) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (3) Pandas (4) PHP (20) Projects (29) Python (929) Python Coding Challenge (351) Python Quiz (21) Python Tips (2) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (3) Software (17) SQL (42) UX Research (1) web application (8) Web development (2) web scraping (2)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses