STRINGS - Handling them like a PRO! 😎

Some in-built functions that can make your task of working around strings a cakewalk!

Thread 🧡
β˜‘οΈ What are STRINGS?
In Python, there is no character! Even a single character is considered a string. Strings are an immutable sequence.

Immutable -> Once strings are created, they cannot be changed.
So, you can't change the string, but the reference to it can be changed.
β˜‘οΈ .split()
a = "this is a string"
a.split()

O/P: ['this', 'is', 'a', 'string']

The string is split into each word in the sentence, considering the DELIMITER as space. The output of the split function is given in a LIST.
DELIMITER -> It is a character or a group of characters that describe how to split the string.

For eg:
a = "this is a string"
a.split("is")

## In the bracket, we defined the delimiter as 'is'}

O/P: ['th', ' ', ' a string']
β˜‘οΈ .replace()
This is used to replace a character or a group of characters with another.

a = "this is a string"
a.replace("this", "that")

O/P: 'that is a string'

The word 'this' is replaced with 'that'.
β˜‘οΈ .strip()
This function returns a copy of the string in which all the characters have been removed (stripped) from the beginning and the end of the string.

For eg:
a = "I am Sukriti. I am a learner. Who am I"
a.strip('I')

O/P: am Sukriti. I am a learner. Who am
Notice that the .strip() method removed the 'I' only from the beginning and the end.

If no argument is passed to the method, it removes blank spaces from the beginning and the end by default.
β˜‘οΈ .find()
It returns the index value for the first occurrence of the passed value in the method.

For eg:
a = "I am Sukriti. I am a learner. Who am I"
a.find('learner')

O/P: 21

The word 'learner' begins from index 21.
Note: The beginning value of the index is zero (0).

To verify:-
a = "I am Sukriti. I am a learner. Who am I"
a.find('I')

O/P: 0

Since the occurrence of the first 'I' is at the beginning, so .find() must return the answer as 0. Hence we got the output as 0.

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with Sukriti Macker

Sukriti Macker Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Sukriti_Macker

9 Jul
Do you know about the SLICING technique that helps you work around strings in Python??

To handle sub-strings, you can use the SLICING method.
πŸ‘‡πŸ‘‡
Let's say we have a string.

a = "This is a string."

You can slice between the string!

πŸ‘‰ a[start_index : end_index : stride]

Terms:-
start_index -> Takes an integer value; this is the index value (inclusive) from where you want to start slicing.
end_index -> Takes an integer value; this is the index value (exclusive) where you want the slicing to end.

stride -> Takes an integer value; indicates how many characters to skip after the first character is retrieved.

Note: The first character index is always 0.
Read 8 tweets
7 Jul
The topic of TRIGGERS is a level-up from creating queries and sub-queries in the handling databases.

A super-easy guide to triggers in SQL πŸ§΅πŸ‘‡
β˜‘οΈ What is a trigger in the laymen (standard) language?

When someone pokes you or does something to agitate you, there is a high chance that you might get 'triggered' automatically! Right?
β˜‘οΈ Triggers in SQL

So, when we say TRIGGERS in SQL, it is simply a stored program that gets executed on its own when a triggering event occurs. Now, triggers are a part of PL/SQL.

PL/SQL is an extension of SQL where SQL queries are used and procedural statements/language.
Read 14 tweets
29 Jun
Hey, here is a compiled version of how to proceed with SQL in a non-threatening way. :)

SQL is fun, easy to grasp and can kick start your programming journey. Learn something for fun and satiate your curiosity. πŸ“š

A Beginner-friendly guide to begin your SQL Journey! πŸ§΅πŸ‘‡
Read 11 tweets
28 Jun
What else can I say about SQL to prove that it is crucial to know how to work around databases?

Having said that, SQL could be the one thing that you could begin your programming journey with. 🀩

A Beginner-friendly version of SQL (UPDATE and DELETE)
πŸ§΅πŸ‘‡
🌟 Let's look at the table first!
The name of the table is -> faculties
We have columns as FacultyId, Name, Class, EmailId and Salary. "Faculties" Table.
β˜‘οΈ UPDATE
This clause is used to change values in a specified column.
You may or may not provide a condition along with the change you want to make.

πŸ‘‰ Update without condition:-
UPDATE table_name SET column_name = column_value;
Read 9 tweets
25 Jun
I hope you are practising SQL whilst you are learning it. This technique makes it easier to understand concepts.

Alrighty, here is another thread for SQL. 🀩

SQL - A Beginner-friendly version! πŸ“š
(Clauses: IN, BETWEEN and LIKE)

Thread 🧡
🌟Which table are we working on today?
The name of the table is "products". So the columns that we have are productCode, productName, productDescription, among others.

Take a look πŸ‘‡ Column namesOverview of the information in the columns
β˜‘οΈ IN
This clause would reduce the efforts to write multiple OR conditions. It helps you find a specific match for a value.

πŸ‘‰ select column1, column2 from table_name where EXPRESSION IN ('value1', 'value2')
Read 15 tweets
24 Jun
Here is another thread of the most important clauses to boost your SQL queries to the next level!

Advance SQL, A beginner-friendly version! (#DataScience)

Thread 🧡
Let me explain what the table looks like.
The table name is customer_list, where the columns are ID, name, address, zip code, phone, city, country, notes & SID.

See the image for reference The table and column names in that table.
β˜‘οΈ GROUP BY
This clause is used to group rows that have the same values together. It summarises data from the database.

Note: The group by clause returns one row for each group.

πŸ‘‰ Query: select col_name from table_name GROUP BY column_name;
Read 13 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(