Trending November 2023 # How Ddl Commands Work In Mysql? # Suggested December 2023 # Top 14 Popular

You are reading the article How Ddl Commands Work In Mysql? updated in November 2023 on the website Minhminhbmm.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested December 2023 How Ddl Commands Work In Mysql?

Introduction to MySQL DDL

MySQL DDL defines the Data Definition Language, a subgroup of SQL commands among four: DDL, DML, DCL, and TCL. Since, Structured Query Language(SQL) is the basic language of a database that performs different operations and queries in the available MySQL database, including creating a database or table to dropping the same and others like updating, inserting, etc. The MySQL DDL gets involved with the schemas and explanations of database to display how the database data should exist in the server. The DDL commands are significant for expressing and altering the structure of database tables, schemas, or objects. The instant effects are taken when the statements using DDL commands in MySQL are implemented.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

How do DDL commands work in MySQL?

The DDL commands work with the SQL query statements, executed to perform and show desired results. Once queried and run, the DDL commands cannot be rolled back and do commit implicitly.

Tables are the database objects that store the data records. These data interact with other table data and form a relation at a structural level. But the data stored requires some modifications from time to time. DDL and different subgroups of SQL in MySQL servers do this.

The user must have required privileges such as CREATE or DROP in the database schemas to work and use DDL queries. We will find DDL commands in all relational databases intended to manage and access the objects in the database.

Examples to Implement MySQL DDL

Let us explain the MySQL DDL commands each with an illustration and show the uses of these queries in the MySQL databases for different administrative tasks:

1. CREATE Command

This DDL command creates any database with different objects, such as tables, indexes, triggers, views, stored procedures, built-in functions, etc.

Code: The CREATE statement is written using the following syntax:

CREATE DATABASE DatabaseName; CREATE TABLE TableName (Column1 Datatype1, Column2 Datatype2,…,ColumnNDatatypeN);

For example, we will create a table named ‘Emp’ with some fields and similar data types that are valid in MySQL and, respectively, a database named ‘EmpDB’ in MySQL server using the queries below:

Code:

CREATE DATABASE EmpDB;

Code:

CREATE TABLE Emp (Emp_ID INT PRIMARY KEY AUTO_INCREMENT, Emp_NameVARCHAR(255), Emp_City VARCHAR(255), Emp_AdmDate DATE NOT NULL);

Output:

We have created the table above with column names, data types, indexes, and keys. For integers, we have used INT data type; for a date, the type of values, we have DATE type; and for character strings with length values, are used as a data type for the Emp table.

2. ALTER Command

The ALTER DDL command modifies the present database structure and related tables.

With Alter query, we can add, alter or delete the present constraints on a table or columns on the table. The syntax is mentioned below:

Code:

ALTER TABLE TableName ADD ColumnNameData_Type; ALTER TABLE TableName DROPColumnName; ALTER TABLE TableName MODIFY COLUMNColumnNameData_Type;

Let us execute some queries with the above structures:

Code:

ALTER TABLE Emp ADD Emp_Contact INT NOT NULL;

Output:

Code:

ALTER TABLE Emp DROP Emp_Contact;

Output:

Code:

select * from `emp`

Output:

Code:

ALTER TABLE Emp MODIFY COLUMN Emp_AdmDateYear;

Output:

3. DROP Command

This MySQL command is used to remove the database objects. In simple words, to delete the table existing in your database using the drop query syntax:

Code:

DROP TABLE TableName;

Code:

DROP Table Emp;

Output:

We need to know that we should be careful while executing the DROP command because it results in the loss of data records that were warehoused in the table.

4. TRUNCATE Command

The Truncate DDL command is implemented to delete all the data rows from the database table, including removing all spaces assigned for those table records.

Code:

TRUNCATE TABLE TableName;

Suppose we are using the above command in the query below:

Code:

TRUNCATE TABLE Emp;

Output:

The output says that the truncate will only remove the records inside the specific table, not the table in the database itself.

5. COMMENT Command

Code:

--We are displaying all records from table Person: SELECT * FROM Person;

Output:

Code:

SELECT * FROM Person --WHERE City = “Delhi”;

Output:

Likewise, we can ignore a whole statement:

Code:

--SELECT * FROM Person; SELECT * FROM Employee;

Output:

Code:

/*selectingall columns from table Employee existing in the database: */ SELECT * FROM Employee;

Output:

To ignore more than one statement:

Code:

/* SELECT * FROM Person; SELECT * FROM Orders; */ SELECT * FROM Employee;

Output:

To ignore any section of the statement given:

Code:

SELECT Person_ID, Employee_Name/*Salary, */ FROM Employee/*GROUP BY Person_ID*/ ORDER BY Employee_Name;

Output:

6. RENAME Command

The Rename DDL command query allows renaming any database objects in the server if needed for any admin works. Sometimes we want to modify the present table name and rename it. For this, let us apply the succeeding syntax with ALTER DDL command:

Code:

ALTER TABLE TableName_ARENAME TO TableName_B;

Explanation with examples:

Code:

ALTER TABLE Emp RENAME TO Emp_Data;

Output:

Code:

select * from `emp_data`

Output:

Conclusion

The MySQL DDL commands allow privileges to the admin users to control the database activities and maintain the flow and access properly. The SQL language used in MySQL provides the managing queries to create a database or table, apply any alterations, and, if needed, drop the database objects, which helps to define the schemas and structures of the database.

Recommended Articles

We hope that this EDUCBA information on “MySQL DDL” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

You're reading How Ddl Commands Work In Mysql?

How Find_In_Set() Function Works In Mysql?

Introduction to MySQL FIND_IN_SET()

MySQL FIND_IN_SET() function is a built-in MySQL string function responsible for discovering the position of a given specific string provided in a list of strings separated by a comma. The FIND_IN_SET() function accepts two arguments that allow matching the first value with the second one containing a list of values as substrings separated by a comma character.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Generally, the FIND_IN_SET() function applies to any field in the database table with a sequence of values differentiated by a comma. The user wants to compare those values with a specific single value. It thus returns the index of the matched string within the list.

Syntax

Following is the syntax structure that illustrates the use of the FIND_IN_SET() function in the MySQL server:

FIND_IN_SET(string1, stringlist);

The initial parameter named string1 defines the string which you need to find.

The next parameter, “stringlist,” represents the list of strings that must be examined, and commas separate these strings.

According to the value of the function arguments, the MySQL FIND_IN_SET() will return the value as an integer or a NULL:

If either function’s parameters, i.e., string1 or stringlist, have a NULL value, the function results in a NULL value.

The function will return zero if the stringlist is empty or if the string1 parameter is not found in the stringlist.

The function returns a positive integer value if the string1 parameter is available in the stringlist.

But note that if the string1 consists of a comma(,), the FIND_IN_SET() function performs poorly on execution. If the string1 parameter is a constant string and the stringlist parameter represents a SET column type, the MySQL server will optimize using bit arithmetic.

How does the FIND_IN_SET() function works in MySQL?

MySQL consists of many databases, and each database comprises different tables. Tables in MySQL store data in various data types supported by MySQL, and the most commonly used types are integers and strings.

When a MySQL user wants to find out if a specific string exits in any of certain sequences of strings divided by a comma(,) symbol aimed for any query execution, then the built-in MySQL string function FIND_IN_SET() can be applied.

This function provides the required value depending on the search results. For example, suppose we are illustrating the following query to show how the function works in MySQL:

We will search a substring h within a list of strings using the statement below,

SELECT FIND_IN_SET("h", "g,h,k,l");

We use the SELECT statement with the FIND_IN_SET() function to evaluate and display the return value. The result from the above query is true as the first parameter, ‘h’ is present in the list as the second parameter. So, Upon execution, the function will produce a positive integer, specifically 2. This is because the first value of the FIND_IN_SET() function is found in the second index of the list of values provided in the function’s second parameter, which is ‘g,h,k,l’.

Similarly, if we take the below query, then the function returns 0 as the output value as the value is not in the list:

SELECT FIND_IN_SET("b", "g,h,k,l");

Also, when we define the query as follows then, the output is NULL as the second parameter is NULL:

SELECT FIND_IN_SET("h", NULL);

Thus, we can define the position of a string within a particular list of substrings provided by the database tables.

Conversely, the MySQL IN operator takes any number of arguments to show if a value matches any value in a set.

Examples of MySQL FIND_IN_SET()

Let us demonstrate some examples using the MySQL FIND_IN_SET() as follows:

Example #1

Example to fetch data from a table by MySQL FIND_IN_SET() function:

Suppose we have a table named collection created in our database using the query below:

CREATE TABLE IF NOT EXISTS Collection (ColID INT AUTO_INCREMENT PRIMARY KEY, ColName VARCHAR(255) NOT NULL, Subjects VARCHAR(255) NOT NULL);

Also, let us enter a few record rows into the Collection table created:

INSERT INTO Collection (ColName, Subjects) VALUES('o-1','Computers, Maths, Science'),('o-2','Networks, Maths, MySQL'),('o-3',' Computers, English, Data Science'),('o-4','Electric, Maths, Science'),('o-5','Computers, MySQL, English'),('o-6','Science, Web Design'),('o-7','Maths, Science'),('o-8','MySQL, Web Design'),('o-9','Computers');

Displaying the contents of the table as follows:

SELECT * FROM Collection;

Now, we will find the collection that will accept the Maths subject using the MySQL function FIND_IN_SET() shown below:

SELECT ColName, Subjects FROM Collection WHERE FIND_IN_SET('Computers', Subjects);

Output:

Looking for a simple example and its output as follows:

SELECT FIND_IN_SET('h', 'g,h,k,l');

Output:

The FIND_IN_SET() function provides the position of the first argument ‘h’ as found in the sequence of values as the second argument of the function.

Example #2

Example showing Negativity of MySQL FIND_IN_SET() function:

Considering the previous table, the result value of the function will be empty when MySQL returns false. This occurs when the substring specified in the first argument is not found in the list of values provided as the second argument. Thus, we will apply the MySQL NOT operator to negate the MySQL function FIND_IN_SET(). Finally, we will illustrate the query example with FIND_IN_SET() function using the NOT operator also to search the collection that does not match the PHP subject in the table values:

SELECT ColName, Subjects FROM Collection WHERE FIND_IN_SET('PHP', Subjects);

As you can see, no output is produced as a collection because, in the list of values from column Subjects, the FIND_IN_SET() function has not found any matched substring as given in the first argument.

Example #3

Difference between IN operator and FIND_IN_SET():

The IN operator defines whether a substring matches any substring set or list and can accept any number of arguments parted by a comma as follows:

SELECT ColName, Subjects FROM Collection WHERE ColName IN ('o-1', 'o-2', 'o-5', 'o-6');

Output:

Similarly, using the FIND_IN_SET() will result in the identical output as IN query but takes only two parameters to show a match of value with a list of values divided by a comma:

SELECT ColName, Subjects FROM Collection WHERE FIND_IN_SET(ColName, 'o-1,o-2,o-5,o-6');

Output:

Conclusion

MySQL FIND_IN_SET() function allows a server to check if a substring as the first argument is present in the list of values composed of substrings in the second argument parted by a comma.

This function, when the value is searched, returns the results based on those values as a positive integer as position(if the value exists in the list), zero(if value not found) or NULL(if any argument is NULL), which can be helpful for MySQL operations at the admin level.

Recommended Articles

We hope that this EDUCBA information on “MySQL FIND_IN_SET()” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

How Does Redirect Work In Javascript?

Introduction to JavaScript Redirect

JavaScript redirect is the process of sending requests form one page to another page through accessing the corresponding URL (Unified Resource Locator). Redirecting URL is also used for sending the user from one URL to another URL. location is the function used in JavaScript to redirect at the specific URL.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Real Time Scenario:

Advantage:

We can add more information within a single page by this URL redirect.

Pre-requisites:

Basic HTML

Basic JavaScript

How does Redirect Work in JavaScript?

JavaScript redirect is working based on different types of redirect methods. Each redirect has its own specification.

Syntax:

location = "URL";

Description: It will set the new location for the current window.

location.href = "URL";

Description: It will set the new href for the current window.

location.assign("URL");

Description: It will assign the new URL to the current window.

location.replace("URL");

Description: It will replace the current window location with a new location.

location = "URL";

Description: It will just set the current window location itself.

location = "URL";

Description: It will set the topmost window location with a current window location.

Note: The difference between href and replace method is replace() method removes the URL of the current document from the document history, means it is not possible to use the “back” button for navigating to the original document.

Examples of JavaScript Redirect

Given below are the examples mentioned:

Example #1

Window location URL.

h1 { text-align: center; color: green; } p { font-size: 28px; border: solid 3px blue; color: maroon; } page to other page through accessing the corresponding URL (Unified Resource Locator). Redirecting URL is also used for sending the user from one URL to another URL. Window.location is the function used in website, while I am reading, I have some doubts with specific topics. Instead of providing everything there itself, we can simply summarize the topic and in between doubtable points can be provide with URL window.location = url;

Output:

After few milliseconds (1sec) moved to URL:

Example #2

Window Location Redirect with Time Limit.

Code:

h1 { text-align: center; color: brown; } p { font-size: 28px; border: solid 3px red; color: green; } input { text-align: center; color: navy; } button { font-size: 22px; font-weight: bold; color: white; background: lightblue; } page to other page through accessing the corresponding URL (Unified Resource Locator). Redirecting URL is also used for sending the user from one URL to another URL. Window.location is the function used in website, while I am reading, I have some doubts with specific topics. Instead of providing everything there itself, we can simply summarize the topic and in between doubtable points can be provide with URL Type URL :<input type=”text” name=”url” function getMyRedirectURL() { var url = document.getElementById(“urlID”).value; document.write(“It will redirect within 3 seconds…..please wait…”);//it will redirect after 3 seconds setTimeout(function() { window.location = url; }, 3000); }

Output:

Example #3

Replace Function URL.

Code:

h1 { text-align: center; color: navy; } p { font-size: 28px; border: double 2px teal; color: lime; } input { text-align: center; color: fuchsia; } .button { text-align: center; } button { font-size: 22px; font-weight: bold; color: white; background: red; } page to other page through accessing the corresponding URL (Unified Resource Locator). Redirecting URL is also used for sending the user from one URL to another URL. Window.location is the function used in website, while I am reading, I have some doubts with specific topics. Instead of providing everything there itself, we can simply summarize the topic and in between doubtable points can be provide with URL function getMyReplaceFun() { }

Output:

Recommended Articles

This is a guide to JavaScript Redirect. Here we discuss the introduction to JavaScript Redirect, working, and examples respectively. You may also have a look at the following articles to learn more –

How Isclose Method Work In Numpy?

Definition of NumPy isclose

Python provides different functions to the users. To work with arrays, the python library provides a numpy function. Numpy is an acronym for numerical python. Numpy performs logical and mathematical operations of arrays. In python, numpy is faster than the list. This is because numpy arrays can be stored at continuous places. Therefore, processing and manipulating can be done efficiently. Numpy isclose method is used to check whether the two given values are close or not. The result of isclose method returns a Boolean value. It means that if the given values are close then it will return ‘true’ otherwise it will return ‘false’. The isclose method uses relative or absolute tolerance to check to check the closeness of values.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

import numpy as np import math math.isclose(p, q, relative_tol=value, absolute_tol=value )

Explanation: In the above syntax where first we import numpy class and access a numpy class as an np, then we import the math library. Generally, in isclose method, we have used the following parameters.

p = this is the first value of isclose method for closeness. This parameter is compulsory for the method.

q = this is the second value of isclose method. It is used to check the closeness of the values. This is a required parameter.

relative_tol = this is an optional parameter called relative tolerance. Relative tolerance is nothing but the maximum difference which is allowed between values p and q. The default value of relative tolerance lies between 1e-09.

absolute_tol = this is an optional parameter called absolute tolerance. Absolute tolerance compares the values which are near to 0. The value of absolute tolerance should be at least 0.

How isclose Method works in NumPy?

We must install Python on your system.

We must install numpy using the pip command.

We required basic knowledge about Python.

We required basic knowledge about numpy.

We can check the closeness of the values.

Examples of NumPy isclose

Let’s see how we can implement isclose method with different examples.

Example #1

Code:

import numpy as anp import math print("First Value is : n", math.isclose(2.555,2.3566)) print("Second Value is : n",math.isclose(2.555,2.555)) print("Third Value is : n",math.isclose(2.555,2.555000001))

Output:

Explanation

We import numpy functions and use them as anp.

We import math libraries.

We use isclose method to check the closeness of values whose closeness is far. Therefore it will return a false value.

Again we use isclose method for the values which are exactly close. Hence it will return a true value.

Further, we use isclose method for the values which are nearly close. Hence it will return a true value.

In the above example, we try to implement math.isclose function. Illustrate the end result of the above declaration by using the use of the following snapshot.

Example #2

Code:

#import numpy and math library import numpy as cnp import math #To check closeness of the values print("Result of both value is : n", cnp.isclose([2,5.5], [2,5.5])) print("Result of both value is : n",cnp.isclose([1e9,1e-7], [1.00001e9,1e-8])) print("Result of both value is : n",cnp.isclose([1e6,1e-9], [1.0001e6,1e-8]))

Output:

Explanation

We import numpy functions and use them as cnp.

We import math libraries.

We use isclose method to check the closeness of two values that are the same close, therefore both values will be true

Again we use isclose method for the two different values which are the first value is exactly close and the second is different. Hence it will return a true and false value.

Further, we use isclose method for the two different values which are the first values are not nearly close and the second value is close. Hence it will return a false and true value.

In the above example, we tried to check multiple values which are closed or not by using isclose and math functions. Illustrate the end result of the above declaration by using the use of the following snapshot.

Example #3

Code:

#import numpy and math library import numpy as cnp import math #To check closeness of the values print("Result of both value is : n",cnp.isclose([2.1, cnp.nan], [2.1, cnp.nan])) print("Result of both value is : n",cnp.isclose([4.1, cnp.nan], [4.1, cnp.nan], equal_nan=True))

Output:

Explanation

We import numpy functions and use them as cnp.

We import math libraries.

We use isclose method to check the closeness of two values which are the first value is close and the second value is missing. Therefore the first value is true and the second value will be false

Similarly, we try to find out closer values by using the same function with different values in which the first value is closer and the second value is missing but here we declared nan equal to true. Therefore both values are true.

In the above example, we have checked if missing values are closer or not by using the same function. Illustrate the end result of the above declaration by using the use of the following snapshot.

Example #4

Code:

# Import math library import math # check closeness of the two values print("Closeness of two values is : n", math.isclose(7.05, 7.06, abs_tol = 0.1)) print("Closeness of two values is : n",math.isclose(4.666, 4.450, abs_tol = 0.150))

Output:

Explanation

First, we import math libraries and access them as math.

Then we check the closeness of two values when we define absolute tolerance. Here absolute tolerance is exactly close so it returns true.

In the second case, we also check the closeness of two values but here absolute tolerance is different. Therefore it returns false.

In the above example, we have implemented isclose function when absolute tolerance is given. Illustrate the end result of the above declaration by using the use of the following snapshot.

Conclusion

We hope from this article you have understood about the numpy isclose function. From the above article, we have learned the basic syntax numpy isclose function. We have also learned how we can implement them in Python with different examples of isclose function as well as we also learned math functions in python. From this article, we have learned how we can handle numpy isclose and math functions in python.

Recommended Articles

This is a guide to NumPy isclose. Here we discuss the introduction and how isclose method work in numpy? along with different examples and its code implementation. You may also have a look at the following articles to learn more –

How Does Sprintf Work In Python?

Definition of sprintf in Python

The sprintf is a function to display the output of the given input using a python programming language.

The sprintf is a print function to shows the output of the format strings in the python language.

It is a coding element to assigns the “f get” method and displays string format output.

The sprintf is a print element to contain string – buffer data of the application and display in the string format using python technology.

The sprintf is a function similar to print, vprint for display buffer output hustle-free.

The python programming language is using the sprintf function to declare argument and constructor elements.

It is an output function to displays all data types like string and array elements.

Syntax:

Start Your Free Software Development Course

The sprintf python works with different data types, lengths of the data, and width.

It has used the percentage sign (%) before the type of the data.

The basic syntax of a sprintf shows below.

% [FLAG WIDTH. (DOT) PRECISION] TYPE

The sprintf python is using the “print” keyword to display output.

print("% [flag width . (dot) precision] type" % (value or object))

The sprintf is used precision and type depends on the data type of the variable. This syntax helps to assign a signed decimal number. The length value of a decimal is 2.

%2d

This syntax helps to assign a binary number. The length value of binary is 4.

%4b

This syntax helps to assign a floating number. The length value of a decimal is 2.1.

%2.1f or %2.1F

This syntax helps to assign ASCII values.

%c

This syntax helps to assign unsigned decimal values.

%u

This syntax helps to assign an octal number.

%o

This syntax helps to assign a hexadecimal number.

%x OR %X

This syntax helps to assign scientific notation of a lowercase.

%e

This syntax helps to assign scientific notation of an uppercase.

%E

This syntax helps to return the type of data format.

%%type How does sprintf work in Python?

Download python software from the respective website. Create a page with the dot (.) py extension. The file name is the “function.py” to write a python program. Create a variable with initializing the required data type value.

Varble_name = 34

Use the print keyword for the string format of the sprint python.

print (write sprint format)

Use percentage sign to return value.

print (" text : %d ")

Display length of the variable or value before data type.

print (" text : %2d ")

Display the type of the variable value in the format helping of the sprint. Use parameter of the percentage sign to end of the sprintf function end. Add variable to interconnect return function and application data.

print (" text : %2d " % (Varble_name))

Use direct value in sprint function to display decimal value.

print("decimal number : %2d " % (7))

Use float type with sprintf formatted value in the return function.

print("Float number : %5.2f" % ( 23.11))

Combine the working procedure of the sprintf python to better understanding.

x = 34 print ("decimal number : %2d " % (x)) print ("decimal number : %2d " % (7)) print ("Float number : %5.2f" % ( 23.11)) Examples Example #1 – Basic

Code:

e_var = 34 print ("decimal number: %2d " % (e_var)) print ("decimal number: %2d " % (7)) print ("Float number: %5.2f" % ( 23.11)) print ("Float number: %5.4f" % (e_var)) print ("Octal number: %5o" % (e_var)) print ("Octal number: %3o" % (42))

Output:

Example #2 – With different types

Code:

e_var = 341234673 print ("decimal number: %d " % (e_var)) print ("Float number: %f" % (e_var)) print ("Float number: %F" % (e_var)) print ("unsigned decimal number: %u" % (e_var)) print ("Octal number: %o" % (e_var)) print ("first string value: %s" % (e_var)) print ("second string value: %s" % ("string data")) print ("first hexadecimal value: %x" % (e_var)) print ("second hexadecimal value: %X" % (e_var)) print ("ASCII value: %c" % ("A")) print ("lowercase scientific notation: %e" % (e_var)) print ("uppercase scientific notation: %E" % (e_var)) print ("first value: %g" % (e_var)) print ("second value: %G" % (e_var))

Output:

Example #3 – With positive and negative value e_var = 341234673 f_var = -341234673 print ("decimal number: %d " % (e_var)) print ("decimal number: %d n " % (f_var)) print ("unsigned decimal number: %u" % (e_var)) print ("unsigned decimal number: %u n" % (f_var)) print ("Octal number: %o" % (e_var)) print ("Octal number: %o n" % (f_var)) print ("first hexadecimal value: %x " % (e_var)) print ("first hexadecimal value: %x n" % (f_var)) print ("second hexadecimal value: %X " % (e_var)) print ("second hexadecimal value: %X n" % (f_var)) print ("lowercase scientific notation: %e" % (e_var)) print ("lowercase scientific notation: %e n" % (f_var)) print ("uppercase scientific notation: %E" % (e_var)) print ("uppercase scientific notation: %E n" % (f_var)) print ("first value: %g" % (e_var)) print ("second value: %G" % (f_var))

Output:

Example #4 – With different length

Code:

e_var = 341234673 f_var = -341234673 print ("decimal number: %2d " % (e_var)) print ("unsigned decimal number: %1u n" % (f_var)) print ("Octal number: %2o n" % (e_var)) print ("first hexadecimal value: %1x " % (e_var)) print ("second hexadecimal value: %5X n" % (e_var)) print ("lowercase scientific notation: %2e" % (e_var)) print ("uppercase scientific notation: %1E n" % (f_var)) print ("Float value: %2.1f" % (e_var)) print ("Float value: %1.2f n" % (f_var)) print ("Octal value: %2o" % (e_var))

Output:

Conclusion

It is easy to return data in any format per application requirement.

It helps to create web applications attractive, understandable, and user-friendly.

Recommended Articles

We hope that this EDUCBA information on “sprintf Python” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

How Does Substring Work In Typescript

Introduction to TypeScript substring

Web development, programming languages, Software testing & others

Syntax:

The TypeScript substring() method mainly focus on the string characters, and it will be used to specify the indexes, and it returns the new substrings characters in the TypeScript. It can be used to pass the two set of arguments one is starting the characters and the second parameter is the length of the string characters.

var variable name="";  console.log("starting position of the character and end position of the character" + variable name.substr(starting position of the character and end position of the character)); ----some typescript codes based on the user requirements-----

The above code is the basic syntax for using the substr() method in TypeScript based applications.

How does substring Work in TypeScript?

The TypeScript string is one of the class for creating and utilising the string characters in the application. We use substring as one of the default method for split the string characters, and it will have concatenated using the length. This method will accept both numeric and non-numeric characters in the script. The string characters are starting with the beginning position of the specific location through the characters for each character; it will calculate the length.

By using the length method, we can calculate the character’s length, and with the help of for loop, we can iterate the values and calculate the character’s length and validate the conditions based on their coder suggestions. Basically, the substring() method is pre-defined, and also it’s an inbuilt function for users to return the subset of the string objects. The argument and the parameters of the substring() method which represents the starting and ending indexes which can be used for to identify the characters and the substring() method which swaps the two set of arguments if the indexStart is greater than the indexEnd position and the string which is still returned position of the variables in the functions.

When we use the string characters index with the help of the indexOf method, the substring method that is not to be used as the really purpose its main job is to return the indexes at the given substring is found on the TypeScript code.

Examples of TypeScript substring

Given below are the examples of TypeScript substring:

Example #1

Code:

var vars = "Welcome to My Domain Have a Nice Day iehf oiefb woeqiurfb iweofbc2iwe bic b newoinu"; var vars1 = "wugdv uidchh e237ed b 374trc hegdc jihefu jehdb jehfb jehb jhebi kbjeij heib jbie h"; var vars2 = "oehqf eub jbqe ijbj jb3e obe bou jbe joj3buier jorub jbj jboui e1r jobeur b ijoe iojef"; var vars3 = "dguy i eebc b eihyeuib f c uiycei ubc3  iurf eurv eub irfub o iobr ibr iu ior iou iub"; var vars4 = "oyed uery euir rui hu48 biury848 buy84 bui fj rhuj hrf hu iho4hi or4ui roh4ih rouiro h"; console.log("(2,3): "    + vars.substr(2,3)); console.log("(-3,4): "   + vars.substr(-3,4)); console.log("(3): "      + vars1.substr(3)); console.log("(-16, 3): " + vars2.substr(-16,3)); console.log("(12, 3): "  + vars2.substr(12,3)); console.log("(15, 5): "  + vars3.substr(15,5)); console.log("(17, 12): "  + vars4.substr(17,12));

Output:

In the above example, we used the substr() method in the different sequences. We used a numeric set of characters that is we can fetch and identified only the integer numbers that will be covered using both positive and negative numbers. With the help of the console.log() method, we can print the values in the output console by using the var keyword; we can declare the variable values by using the string quotations. Generally, the var datatype includes numeric and non-numeric characters here; we can cover the numeric value with the specified index positions for each step, and the variable values declared in the user input end.

Example #2

Code:

var vars = "Welcome to My Domain Have a Nice Day iehf okjwdkg kewgk jdgkiwye iugeigu buir br"; var vars1 = "wuhsgf jdghj 326875 38 3846 86347484 8634r 39846 468 48465 386 34798 94865 946"; var vars2 = "f wqd qw qwuef3287 j6487 jg857 kjg85 jy4587 ng875 gr8 jgweuf 478 jgeru 74"; var vars3 = " hjqwdf jhgds ieyw jhgu jhger 457 jgevr u5 jbi5t78 njerv 5u jngu5 biu5yn bnn uy5 r"; var vars4 = "wf jhqgwf37 jhg u4t jhuy bvu5y4 bv5n bv457b u45t7 bu54tg biu45y buy55y jhgu b ut bu"; var vars5 = new String( "Have a Nice Day" ); var ind = vars.indexOf( "jg jdsvh jsjv bj b kjbd sdbsksd bs dbs db bd" ); console.log("Your first output result is :" + ind ); console.log("Your second output result is:" + ind1 );

Output:

In the second example, we used indexOf() is one of the default child methods in the substring() method; with the help of this method, we can fetch and retrieve the indexing values and the position of the string characters. Additionally, we used var5 variable values; we can create the string object and store it as the separate memory address and its reference.

Example #3 var vars = "Welcome to My Domain Have a Nice Day iehf okjwdkg kewgk jdgkiwye iugeigu buir br"; var output = /My/gi; if (vars.search(output) == -1 ) { console.log("Sorry user it does not contain your values" ); } else { console.log("Thanks user it contains  your values" ); }

Output:

In the final example, we used the search() method for searching the characters, which is declared on the user input variable. We can also search and store the input characters using the other variable with the same data type(var). The search() method is one of the child method in the substring() function of the string classes.

Conclusion

The substring() method is one of the default and frequently used as the string classes in TypeScript. With the help of its child methods like search(), indexOf(), substr() methods, we can achieve this functionality like to calculate the starting and indexing position of the string characters and using loop/conditional statements for evaluating the values.

Recommended Articles

We hope that this EDUCBA information on “TypeScript substring” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Update the detailed information about How Ddl Commands Work In Mysql? on the Minhminhbmm.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!