1627029480
Looking for a way to add interaction to client logos and matching testimonials? With Divi’s responsive content feature, it’s now easier than ever to show different content in a module’s default state and on hover.
In today’s Divi tutorial, we’ll demonstrate that by showing you how to replace client logos with testimonials on hover (desktop) and click (tablet and phone). We’ll use the Blurb Module to help us get there! You’ll be able to download the layout’s JSON file for free as well!
#divi #json
1627029480
Looking for a way to add interaction to client logos and matching testimonials? With Divi’s responsive content feature, it’s now easier than ever to show different content in a module’s default state and on hover.
In today’s Divi tutorial, we’ll demonstrate that by showing you how to replace client logos with testimonials on hover (desktop) and click (tablet and phone). We’ll use the Blurb Module to help us get there! You’ll be able to download the layout’s JSON file for free as well!
#divi #json
1669174554
In this article, we will learn how to replace elements in Python NumPy Array. To replace elements in Python NumPy Array, We can follow the following examples.
The following code shows how to replace all elements in the NumPy array equal to 8 with a new value of 20:
#replace all elements equal to 8 with 20
my_array[my_array == 8] = 20
#view updated array
print(my_array)
[ 4 5 5 7 20 20 9 12]
The following code shows how to replace all elements in the NumPy array greater than 8 with a new value of 20:
#replace all elements greater than 8 with 20
my_array[my_array > 8] = 20
#view updated array
print(my_array)
[ 4 5 5 7 8 8 20 20]
The following code shows how to replace all elements in the NumPy array greater than 8 or less than 6 with a new value of 20:
#replace all elements greater than 8 or less than 6 with a new value of 20
my_array[(my_array > 8) | (my_array < 6)] = 20
#view updated array
print(my_array)
[20 20 20 7 8 8 20 20]
1643114838
In this article you'll see how to use Python's .replace()
method to perform substring substiution.
You'll also see how to perform case-insensitive substring substitution.
Let's get started!
.replace()
Python method do?When using the .replace()
Python method, you are able to replace every instance of one specific character with a new one. You can even replace a whole string of text with a new line of text that you specify.
The .replace()
method returns a copy of a string. This means that the old substring remains the same, but a new copy gets created – with all of the old text having been replaced by the new text.
.replace()
Python method work? A Syntax BreakdownThe syntax for the .replace()
method looks like this:
string.replace(old_text, new_text, count)
Let's break it down:
old_text
is the first required parameter that .replace()
accepts. It's the old character or text that you want to replace. Enclose this in quotation marks.new_text
is the second required parameter that .replace()
accepts. It's the new character or text which you want to replace the old character/text with. This parameter also needs to be enclosed in quotation marks.count
is the optional third parameter that .replace()
accepts. By default, .replace()
will replace all instances of the substring. However, you can use count
to specify the number of occurrences you want to be replaced..replace()
Method Code ExamplesTo change all instances of a single character, you would do the following:
phrase = "I like to learn coding on the go"
# replace all instances of 'o' with 'a'
substituted_phrase = phrase.replace("o", "a" )
print(phrase)
print(substituted_phrase)
#output
#I like to learn coding on the go
#I like ta learn cading an the ga
In the example above, each word that contained the character o
is replaced with the character a
.
In that example there were four instances of the character o
. Specifically, it was found in the words to
, coding
, on
, and go
.
What if you only wanted to change two words, like to
and coding
, to contain a
instead of o
?
To change only two instances of a single character, you would use the count
parameter and set it to two:
phrase = "I like to learn coding on the go"
# replace only the first two instances of 'o' with 'a'
substituted_phrase = phrase.replace("o", "a", 2 )
print(phrase)
print(substituted_phrase)
#output
#I like to learn coding on the go
#I like ta learn cading on the go
If you only wanted to change the first instance of a single character, you would set the count
parameter to one:
phrase = "I like to learn coding on the go"
# replace only the first instance of 'o' with 'a'
substituted_phrase = phrase.replace("o", "a", 1 )
print(phrase)
print(substituted_phrase)
#output
#I like to learn coding on the go
#I like ta learn coding on the go
To change more than one character, the process looks similar.
phrase = "The sun is strong today. I don't really like sun."
#replace all instances of the word 'sun' with 'wind'
substituted_phrase = phrase.replace("sun", "wind")
print(phrase)
print(substituted_phrase)
#output
#The sun is strong today. I don't really like sun.
#The wind is strong today. I don't really like wind.
In the example above, the word sun
was replaced with the word wind
.
If you wanted to change only the first instance of sun
to wind
, you would use the count
parameter and set it to one.
phrase = "The sun is strong today. I don't really like sun."
#replace only the first instance of the word 'sun' with 'wind'
substituted_phrase = phrase.replace("sun", "wind", 1)
print(phrase)
print(substituted_phrase)
#output
#The sun is strong today. I don't really like sun.
#The wind is strong today. I don't really like sun.
Let's take a look at another example.
phrase = "I am learning Ruby. I really enjoy the ruby programming language!"
#replace the text "Ruby" with "Python"
substituted_text = phrase.replace("Ruby", "Python")
print(substituted_text)
#output
#I am learning Python. I really enjoy the ruby programming language!
In this case, what I really wanted to do was to replace all instances of the word Ruby
with Python
.
However, there was the word ruby
with a lowercase r
, which I would also like to change.
Because the first letter was in lowercase, and not uppercase as I specified with Ruby
, it remained the same and didn't change to Python
.
The .replace()
method is case-sensitive, and therefore it performs a case-sensitive substring substitution.
In order to perform a case-insensitive substring substitution you would have to do something different.
You would need to use the re.sub()
function and use the re.IGNORECASE
flag.
To use re.sub()
you need to:
re
module, via import re
.pattern
.replace
the pattern.string
you want to perform this operation on.count
parameter to make the replacement more precise and specify the maximum number of replacements you want to take place.re.IGNORECASE
flag tells the regular expression to perform a case-insensitive match.So, all together the syntax looks like this:
import re
re.sub(pattern, replace, string, count, flags)
Taking the example from earlier:
phrase = "I am learning Ruby. I really enjoy the ruby programming language!"
This is how I would replace both Ruby
and ruby
with Python
:
import re
phrase = "I am learning Ruby. I really enjoy the ruby programming language!"
phrase = re.sub("Ruby","Python", phrase, flags=re.IGNORECASE)
print(phrase)
#output
#I am learning Python. I really enjoy the Python programming language!
And there you have it - you now know the basics of substring substitution. Hopefully you found this guide helpful.
To learn more about Python, check out freeCodeCamp's Scientific Computing with Python Certification.
You'll start from the basics and learn in an interacitve and beginner-friendly way. You'll also build five projects at the end to put into practice and help reinforce what you learned.
Thanks for reading and happy coding!
1627849140
Ever since the Divi sticky options have come out, endless interaction design possibilities have been added to our Divi toolboxes. Besides being able to turn a header sticky on scroll, you’re also able to change the style of your elements in a sticky state. This allows you to highlight your header once it’s turned sticky, and create another user experience while people are reading through your pages and posts.
One of the questions that’s been often asked is in the community is how to can change the Divi logo in a sticky state. In this tutorial, we’ll show you a quick and easy way to do that. We’ll start the tutorial by building a global header, then we’ll apply the sticky effects and in the third part of the tutorial, we’ll show you how to change your sticky logo on scroll. If you’re already familiar with Divi’s sticky options and global header possibilities, feel free to skip to the third part of the tutorial to see the few steps needed to change your sticky logo on scroll.
#logo #divi
1628369280
Optimizing your site’s logo in Divi is an important part of the design of your website. But, it doesn’t have to be a mysterious or daunting endeavor. In fact, Divi makes it pretty simple with the Divi Theme Builder and all of the built-in design options available.
In this tutorial, we are going to show you how to optimize your logos with the right size, position, and style in Divi. Then we’ll show you how to save those designs as global presets you can use for future development.
#global #divi #logo