Monday, 29 November 2021
Saturday, 27 November 2021
Sequence Data Part 5 | Day 9 | General Sequence Data Methods | Part I
Author November 27, 2021 Python No comments
General Sequence Data Methods | Part I
Some of the methods that we can apply on any sequential data.
So basically Python methods are like a Python function, but it must be called on an object.
And Python also has a set of built in methods that you can use on sequential data, but note that the method is going to written new values, but they are not going to change the original data at all. So we are going to look at few examples on how we can call the methods on the given sequential data.
String Methods
4) .find() - And you can also find the index of a given letter, for example, if you want to particularly know the index of a given character then you can give that inside the find method. So that should be given the single quote. So the index of n is 4.
6) .replace() - Using the method replace you will be able to replace any word with the given word. For example, you can apply or you can call that on the string and that is strsample and inside method you can just give string to be searched that is fun. So we are searching for the word fun in the strsample string and I am going to replace fun with joyful. So let me just try this. So you are getting learn is joyful. Instead of getting learn is fun which was the original string.
Friday, 26 November 2021
Java Oops Concept
Irawen November 26, 2021 Java No comments
Java Oops Concept:
1. Objects
2. Class
3. Inheritance
4. Polymorphism
5. Abstraction
6. Encapsulation
Object :
Any entity that has state and behaviour is known as an Object.
An object can be defined as an instance of a class.
Example :
Object = {property 1: value1, property 2: value 2……property n: value n}
Class :
- Collection of object is called class.
- It is a logical entity
- Class doesn’t consume any space.
- A class can also be defined as a blueprint from which you can create an individual object.
Inheritance :
When one object acquires all the properties and behaviours of a parent object, it is known as inheritance.
It provides code reusability.
It is a used to achieve runtime polymorphism.
Polymorphism :
If one task is performed in different way, it is known as polymorphism.
In java we use method overloading and method overriding.
Abstraction :
Hinding internal details and showing functionality is known as abstraction.
Encapsulation :
Binding or wrapping code and data together into a single unit are known as encapsulation.
Naming Convention :
1. Class
. It should start with the uppercase letter.
It should be a noun such as Color, Button, System, Thread, etc.
Use appropriate words, instead of acronyms.
Example :
Public class Employee {
//code snippet
}
2. Interface
It should start with the uppercase letter.
It should be an adjective such as Runnable, Remote, ActionListener.
Use appropriate words, instead of acronyms.
Example :
Interface Printable
{
//code snippet
}
3. Method
It should start with lowercase letter.
It should be a verb such as main(), print(),
println().
If the name contains multiple words, start it
with a lowercase letter followed by an uppercase letter such as
actionPerformed().
Example :
Class Employee
{
//method
Void get( )
{
//code snippet
}
}
4. Variables
It should start with a lowercase letter such as id, name.
It should not start with the special characters like & (ampersand), $ (dollar), _ (underscore).
If the name contains multiple words, start it with the lowercase letter followed by an uppercase letter such as firstName, lastName.
Avoid using one-character variables such as x, y, z.
Example :
Class Employee
{
// variables
Int id;
Char name;
}
5. Package
It should be a lowercase letter such as java, lang.
If the name contains multiple words, it should
be separated by dots (.) such as java.util, java.lang.
Example :
Package com.abc.xyz;
Class employee
{
//code
}
6. Constant
It should be in uppercase letters such as RED, YELLOW.
If the name contains multiple words, it should be separated by an underscore(_) such as MAX_PRIORITY.
It may contain digits but not as the first letter.
Example :
Class Employee
{
//constant
Static final int MIN_Age = 18;
//code
}
Object and class Example:
Public class Student {
Int id ;
String name;
Public static void main (String[] args)
{
Student s1 = new Student();
System.out.println(s1.id);
System.out.println(s1.name);
}
}
Syntax of class :
Class <class_name>{
Field;
Method;
}
Class Student {
Int rollno;
String name;
Void insertRecord(int r, String n)
{
Rollno = r;
Name = n;
}
Void display()
{
System.out.println(rollno+ “ “ +name);
}
Class StudentTest {
Public static void main (String[] args)
{
Student s1 = new student();
Student s2 = new Student();
S1.insertRecord(101, “Ram”);
S2.insertRecord(102, “Sita”);
S1.display();
S2.display();
}
}
Class Student {
Int id;
String name;
}
Class StudentTest {
Public static void main (String arg[])
{
Student s1 = new Student();
Student s2 = new student();
S1.id = 101;
S1.name = “Ram”;
S2.id = 102;
S2.name = “Sita”;
System.out.println(s1.id+ “ “ s1.name);
System.out.println(s2.id+ “ “ s2.name);
}
}
Sequence DataType Part - IV [Concatenation and Multiplication]
Author November 26, 2021 Python No comments
Sequence Data Operations : Concatenation
Syntax : '+' , '+='
Wednesday, 24 November 2021
Sequence DataType Part - III [Slicing]
Author November 24, 2021 Python No comments
Sequence data operations: Slicing
String Slicing
List Slicing
Dictionary Slicing
Set Slicing
Tuesday, 23 November 2021
Sequence DataType Part - II [Indexing]
Author November 23, 2021 Python No comments
Sequence data operations: Indexing
String Indexing
List Indexing
Array Indexing
Dictionary Indexing
Range Indexing
Popular Posts
-
What is the result of this code? x = {1: "a"} y = x print(x is y) Explanation: 1. What the is Operator Does The is operator ch...
-
1. Basic Function Syntax What will be the output of the following code? def greet(name="Guest"): return f"Hello, {name}!...
-
The code snippet in the image is invalid and will raise an exception. Here's why: Explanation: 1. Class TV Definition: class...
-
a = (1 << 52) print((a + 0.5) == a) Code Explanation: a = (1 << 52) print((a + 0.5) == a) 1 << 52: The << operator i...
-
The code snippet is an example of Python multiple inheritance, and here’s the explanation of the output: Code Analysis: 1. Class...
-
a = (1 << 52) print((a + 0.5) == a) This Python code explores the behavior of floating-point numbers when precision is stretched to t...
-
Through a recent series of breakthroughs, deep learning has boosted the entire field of machine learning. Now, even programmers who know c...
-
Explanation Evaluating "Hello" * 3: "Hello" * 3 repeats the string "Hello" three times: "HelloHelloHell...
-
Explanation Parentheses and Multiplication: "Python" * 2 The string "Python" is repeated twice using the multiplicat...
-
def my_generator(): for i in range(3): yield i gen = my_generator() print(next(gen)) print(next(gen)) Explanation: my_generato...