Creation and use of strings

--Originally published at Py(t)hon

This is very easy to learn, first to create a string what you should do is enclose all the characters between quotes like this Ex: str1= “Hello”, this is a string already.

You can play with the string and updated, change it, add more, print it completely, print it partially etc.

str1

Here is a video of strings:

That’s all #Pug#Tec#TC101#Strings#TheEnd

 


Strings

--Originally published at Hector Martinez Alcantara

A string is an array of characters like a word or a phrase which have some properties or specific functions to modify or analyze the string.

First, how to inicialize it?

var="Hello world"

All the characters between the quotes are part of the string, but how to access it?

print(var) #The result is 'Hello world'
print(var[3]) #The result is 'l'
print(var[0:4]) #The result is 'Hello'

You can modify the strings like this:

var="Another value to the string" #Modifying all the string
#Result: Another value to the string
var= var + " with something more" #Add characters to the string
#Result: Another value to the string with something more
a="Something"
a=a * 3 #Repeating the string
#Result: SomethingSomethingSomething

You can also access to strings into another string made by a print with the operator %s:

var="Another value to the string" 
a="Something"
print("There are %s i want to say, like: %s" %(a,var))
#Result: "There are Something i want to say, like: Another value to the string"

As you can see, you access the strings in the %() in order that they were write

There’s a lot of types of values you can acess in a string, like the table below.

Format Symbol Conversion
%c character
%s string conversion via str() prior to formatting
%i signed decimal integer
%d signed decimal integer
%u unsigned decimal integer
%o octal integer
%x hexadecimal integer (lowercase letters)
%X hexadecimal integer (UPPERcase letters)
%e exponential notation (with lowercase ‘e’)
%E exponential notation (with UPPERcase ‘E’)
%f floating point real number
%g the shorter of %f and %e
%G the shorter of %f and %E

And also there are some functions prefurbished to the strings listed in the table below:

Methods with Description
capitalize()
Capitalizes first letter of string
center(width, fillchar)

Returns a string padded with fillchar with the

Continue reading "Strings"

Creation of sytrings and how to use them

--Originally published at Luis Santana's Blog

This blog is really special to me, and I would like to take a minute to explain it why. This post means that I’m half way there and just missing four posts.

2002

In this post I will talk about strings and how to create them. In order to create a string you should enclose your text in quotes, (it is the same if you use single quotes or double quotes). You can see an example below:

string

Check this link if you want to learn more about strings: https://www.tutorialspoint.com/python/python_strings.htm

 


Strings

--Originally published at Python

Creating and using strings is simple. You just need to define a variable  using an apostrophe. Ex: string1 = ‘Hello’

After this, you can play around with the string. You can update it, print all of it, print only some parts, etc. Here are some examples:

Code:

str1 = ‘I like dogs’

print(str1)
print(str1[0])
print(str1[7:10])

2strings

As you can see, it’s easy, you just need to understand the positioning and how everything inside of it is arranged.


Strings

--Originally published at Newbie Programmer

giphy
Welcome to a new post

In this post we have an introduction to strings of python 3.

First, the strings can be enclosed in single quotes (‘ ‘) or doble quotes (” “).

strings1strings2

You can put \ to scape single quote or put instead double qoutes ” “

doesnt

The print () function

print.gif

printprint2

\n Character

nn2

If you dont like to expect a new line, you can put letter r before the quotes.

r1r2

Operator \t

t1 t2

If you want to span in multiple lines , you can put triple quotes( ¨¨¨     ¨¨¨)

triple1triple2

Properties of the strings.

p1p1-1

Indexed

i1i1-1

Slicing

s0-1s1

Strings learned.

before

And its the end.

 

 

 


No strings attached

--Originally published at Programming

Creation and use of Strings

Today, we are going to be talking about a very simple topic, how to create and use strings in Python. You may think that you’ve already mastered the art of strings, but you would be surprised if you knew that you don’t know the full potential of strings. Let’s begin.

A string is one of the most popular data types in Python, they can be created by surrounding a sentence in double quotes “” or single quotes ”. You use them when you print them out to the console and when you assign a string to a variable.

Access substrings in Strings

Unlike other languages, Python does not support the character type, so any value that is contained within a string is going to be called substrings. To access is pretty simple, since it is the same as if we had a list and we wanted to get the value at i position. 1.png

Slicing Strings

Just like with lists, we can slice a string by using the square brackets along with the indices to obtain the new string.

2.png

3.png

Non Printable Characters

If you use a non printable character inside a string, they are not going to be printed. These non printable characters, also called escape characters, are not going to be printed by the console, instead they are going to make some changes to you string. Don’t worry if you don’w understand yet, let me use some examples.

4.png

5.png

Special Operators

Here is a list with examples of the most important string operators that you are eventually going to be using.

6.png

7.png

Built-in String Methods (Functions)

As you should remember, lists have their methods to manipulate and insert data. Some examples for those methods are the append() or the insert(). But fortunately strings have also their own set

Continue reading "No strings attached"