Skip to content

Kenan YAMAN

Dışı tekniker, içi yazılımcı

Menu
Menu

Python Escape chracters

Posted on 26 December 201923 January 2021 by Kenan

If you’re engaged in programming and interested, you’ve seen or heard escape signs or escape sequences from somewhere. You’re very likely to make this mistake at the end of many of the busiest hours and shifts of many projects!!! As with many reasons for this, the most common and overlooked problem is the forgetfulness of escape signs. A lot of people who are new to programming in particular often encounter it.

What are these escape sequences? When we want to use the signs or characters in python seductive, which means special meaning, we encounter these escape sequences.

For example, when we want to define a string in python, we can do it in three different ways. Using single quotes double nails or three nails. Let’s think of a scenario like this, we have a character index, and we need to use one nail here.

'This is Sakarya' 

If we use it this way, python will form the character index after the first nail and finish the character index when it reaches the quotation mark at the end of the word Sakarya. The rest of the “dir” supplement will give syntax error because it does not know what it means.

In order to avoid this and a lot of other mistakes, we need to know the escape sequences. Let’s get started 🙂

Reverse Taksim ()

Now that you’ve researched these issues and come to this page, I think you know how to define strings in python. We can use three different methods, as I mentioned above when defining strings. I want to continue with the example I gave you above. When you define a string like this:

"This is Sakarya".
When defining a string, syntax error error

We know we’re going to get a mistake. We said there were three different ways to define strings, so can’t we just define a string? [baglanti_kare][space]

"This is Sakarya"

We can do it and we don’t deal with any syntax error errors.

Define string with a pair and use a single quotation mark

We can even make a description like this:

""This is Sakarya""

We do not encounter any errors with this definition, but when we have to define a string with one fingernail, double quoteor three quotes, our help is running a reverse taksim sign 🙂

For this, using the reverse cab before the quotation mark pythona, it does not end the string with the quotation mark, it gives the message there is more to the continuation. And when the python sees this, he’s looking for a second nail mark that will continue to run and finish the string. When he finds the quotation mark, he finishes the string identification. Let’s do an impression right away on the same sample

'This is Sakarya''
Use of reverse cab sign with single nail

When we type the code in this way, we will not encounter any errors.

The same code applies in double quotes and three quotes.

Use of reverse cab sign with double nail

But where are we going to need this? Let’s think of a scenario, you want to send a message to the user, you can use the reverse taksim sign. You have read a character index from within a text file, and you will process it on the character index, but you cannot interfere with it, which is in case python will error if you want to use the character sequence you received. You can edit it and use reverse division before quotation marks.

Line per Line (n)

n character sequence is a special character that is to switch to a subline in a python. We use this special character between long-line text to go downto the bottom line at any time and keep the program running.

But the thing is, if this particular character is in a description and we want to use that description, it can cause unexpected output. Therefore, it is one of the things that should be considered in particular.

Let’s think of a scenario like this, let’s put the path to a file on our computer, but if a “n” character comes up to the reverse taksim sign in this file path, we’ll be involuntarily using another special set of characters for python. So python is not the output we want, but whatever special character we’re using at that moment, it’s going to function. Let’s make an example now:

'C:pulsepatients.txt'

When we make such a description, when the python n character (pulse) goes to the part where it is, it switches to a bottom line and continues to function. In fact, what we wanted to do was put the path to a file on our computer on the screen.

In this case, if we do not know that the character sequence n has a special meaning, it will be inevitable that the applications we write will yield unexpected results.

Let’s think of a scenario in this. For example, you want to open a file on your computer with an open() function, and you have a nod as I sample duped as a file path. In this case, the program you typed will not work. And it’ll cause it to collapse.

To prevent this, you can double use the reverse cab marks in the directory. Thus, it will not cause any mistakes.[yazi_ici_goruntu][space]

Double reverse taxi use

Tab (t)

Just like in the character “n”, if the reverse taksim sign comes before the letter “t”, a special character appears in the sense of tab for python.

For example, we use the t character index to leave a tably space in text.

t escape sign usage

Creates four spaces on the screen as if once pressed on the tab tab

It works for us when we use this escape sign on purpose, but it negatively affects the functioning of the practice we write when we miss it.

Let’s continue using the example we use in the n custom character sequence.

'C:pulseblood pressurepatients.txt'

when we do a definition in the form of a definition, we encounter a result like this.

t escape sign example

n progresses to the python functioning by reading codes from left to right, as in a special character sequence, the reverse split sign twice to let the n character sequence know that we are using it for a different purpose, not to actually switch to a new line We write, we continue to read the codes, when you see the t sign, interpret that it is written for a new tab, leaving a tab space, presses the rest of the post to the screen.

To prevent this, we can use a double reverse division, just like we used in the n escape directory. This allows us to let the python know that this is not actually a tab mark

t escape sign example

Ringtone (a)

A special character index formed by the inverse split sign when another letter is next to each other is the letter “a”. When these two characters come together, they cause beep.

You might want to try this. This does not work on linux systems. It does not work on every windows system. It causes such an effect in some versions.

Don’t forget to consider this when working with Strings.[baglanti_kare][space]

Same Line per Line (r)

This letter, which is critical in our alphabet and often we use in sentences, consists of a line-by-line escape sequence with the side-by-side of the reverse division.

When this escape sequence runs, it writes the characters after where it was located on the entire character written before its location. Let’s make an example right away.

"I'm learning python"
r escape directory example

Python begins interpreting the code that is written from the left, returns to the beginning of the line after the “python” article, and writes the word “I’m learning.” Let’s make another example.

"I'm learningrpython"
r escape directory example

Python reinterprets starting from the left, when it comes to the “r” escape directory, writes it at the beginning of the line as it is when the word comes after the escape directory, and adds more characters left over from the first word. The word “I’m learning” consists of 11 characters, the word “python” consists of 6 characters, so the word “I’m learning” is written in six characters, and the remaining four characters are added to the word “python”. We came across this strange word as it came out of “pythonming” 🙂

Cursor Scrolling (b)

The task of this escape sequence is to shift the cursor to the left of a character. Let’s make an example right now.

"Kenan yaman"
b escape directory

Under normal circumstances, I used the “b” escape sequence after a gap and space between the words “Kenan” and “egregious”. The result is a contiguous version of the two words. When this code came to the escape directory while interpreting it, a character shifted the cursor to the left and gave the screen an output like this.

Let’s write the same sample without a space.

b escape directory example

This time, when it came to the escape directory, the cursor slipped to the left of a character and wrote it over the letter “n.” So a character has been deleted.

You can scroll to the left as many cursors as you want by typing this escape directory side by side many times.

Little Unicode (u)

We’re on a dangerous escape sequence. First of all, let’s define what unicode is

Unicode: A system in which all characters you see on a computer screen are uniquely defined by custom numbers (letters, numbers, numbers, special characters). We like nuptify this, every device with an internet output has a unique mac address. In this system, codes that are unique and custom-made for each character like it.

You can look at this link for Latin letters and see this link for other letters and symbols

Python looks for a unicode character that you see side by side with the reverse division and “u” characters. He makes an error when he can’t find it. If we miss this in the apps we write, we could cause the program to crash. Let’s set an example.

File location: C:usersdocumentspython.pdf

When we want to output the screen like this, the python interpreter reads the code starting from the left and looks for a unicode in subsequent characters when the escape sequence arrives. If he can’t find it, it’ll cause an error.

As with other escape sequences, you can pair the reverse taksim sign to overcome this problem.[yazi_ici_goruntu][space]

Great Unicode (U)

The capitalized escape sequence means the same meaning as any other escape sequence written in the same lowercase letter. The only difference between them is that the lower unicode holds a 4-character field, while the capitalletter-typed unicode holds an eight-character field.

To type the character “i”, we need to write a code with little unicode.

'u0131'

The big unicode uses this to write the same character.

'U00000131'

Long Name (N)

Another escape sequence related to Unicode is the escape series written with the letter “N”.

A unique long “name” is also used in the Unicode system as well as a unique code. The unique long name used for the letter “a” is as follows “LATIN SMALL LETTER A”

You can look at the long names of all letters via the link I give above.

As with other unicode escape sequences, python will make an error because it cannot find a response if it does not see any long name unicode identification when it comes to the escape directory.

Hexadecimal Character (x)

As with other escape sequences, when the reverse division and the letter “x” come together, it produces an escape sequence for the hexadecimal counting system.

In the hexadecimal counting system, as in unicode, each letter and number have a equivalent. We can see this with a code like this.

x escape sequence example

The “x6b” of the hexadecimal system is used for the letter “k”. You can use this site to look at all characters and symbols.


Finally, I want to show you how we can get rid of these escape sequences in a more practical way.

If an escape sequence falls like this in a string, you put the letter “r” at the beginning of the string, python will ignore these escape sequences. Let’s set an example.

print(r'C:pulseblood pressurepatients.txt')

In normal circumstances, when we wanted to make an example like the above, we would have inadvertently used the n and t escape sequences, but we neutralized these escape sequences with a single letter “r” that we used before the quotation mark.

Disable escape sequences

Our good understanding of escape sequences is important for the health of the programs we will write. You never know where or when these characters will appear.

We’re at the end of the escape sequences. Hope you write code without errors and problems…. 🙂

[baglanti_kare][space]

Bunu paylaş:

  • Twitter
  • Facebook

Related

Leave a Reply Cancel reply

Categories

  • Console
  • Django-en
  • English
  • General
  • Hardware
  • Kick-off information
  • Linux-en
  • Python-en
  • Software
  • TürkçeTürkçe

Personal VPN setup

Personal vpn setup

RSS Rss

  • Samsung np s3511 laptop fan temizliği, termal macun değişimi ve parça değişimi (RAM, HDD,Cd room,CPU ) 12 October 2021
    Herkese merhaba, uzun zamandır bir laptop söküp bakım yapmamıştım. Eski bir arkadaşım laptopuında ısınma ve kapanma sorunları olduğunu söyledi. Bir hafta sonu misafirliğe giderek laptopa güzel bir temizlik yaptık. Temizlik yaparken yaptığım işlemleri resim çekerek görselleştirdim. Ben temizlik için laptopu söktüm fakat sadece temizlik yapmak dışında bu yazınında başlığında gördüğünüz gibi parça değişimi işlemleri içinde...
  • Linux işletim sisteminin yanına windows işletim sistemi nasıl kurulur ? [Dual boot] 28 June 2021
    Herkese merhaba, bugün ki konumuz dual boot, bir başka değişle; bilgisayarınızda yüklü olan işletim sisteminin yanına bir başka işletim sistemi kurmak. Uzun yıllar Windows kullanmış bir birey olarak, yaklaşık 5-6 yıldır Linux tabanlı işletim sistemleri kullanıyorum. Uygulama geliştiricelerin kullanırken daha rahat hissetiği ve işletim sistemi üzerinde tam kontrole sahip olduğu bir işletim sistemi. Bunun yanı...
  • Docker nedir, Docker ile neler yapılır ? 14 June 2021
    Herkese merhaba, sitemin temasını değiştirdim ve bir kaç bileşen eklemesi yaptım. Bri şeyi fark ettim, bir kaç yıldır blog yazıyorum fakat bloğumda arşiv kısmına baktığımda bir kaç ay hariç geri kalan aylarda neredeyse sadece bir adet yazı paylaşmışım. Düşünüyorum; ayda bir yazıdan fazla blog yazmış olmam gerekiyor. Ama gerçekte öyle değilmiş. Neyse, bu durum bloğun...
  • Linux uyku modları ve sorunları 22 May 2021
    Herkese merhaba, uzun zamandır blog yazamıyorum. İş değiştirme olsun yaşadığım sorunlar olsun bir türlü vakit ayırıp içerik hazırlayamadım. Kendi bilgisayarım üzerinde yaşadığım bir sorunu nasıl çözdüğümü yazarak başlamak istiyorum. Öncelikle hikayenin başına dönelim. Önceki yazılarımı okuyanlar bilir, askerden geldikten sonra yaptığım ilk iş bilgisayarıma format atmak oldu. Herşeye sıfırdan başladım. Buraya kadar bir problem yok...
  • WordPress, web sitenizde kritik bir hata oluştu! 3 April 2021
    Herkese merhaba, uzun süredir içerik üretemedim ve fazla vakit ayıramadım buralara, yeterince vakit bulamadım işin açıkcası. Bulduğum ilk fırsatta bir iki yazı yazmak istedim. İlk yazım wordpress kullanan her kullanıcının başına gelebilecek türden bir hata. Bir gün web sitenize girmek istediniz ve karşınıza böyle bir ekran geldi. [goruntu_kare][goruntu_kare_amp] Siz en son bıraktığınızda siteniz güzel ve...
  • İnternette Kişisel Güvenlik 24 January 2021
    Geçtiğimiz günlerde WhatsApp’ın güncellediği kişisel veri ilkesiyle ülkemizde büyük ses getird. Bununla birlikte telefonumuzda ya da bilgisayarımızda kullandığımız uygulamaların ne tür verileri sakladığını ve bu verileri ne amaçla kullandığını bilmek kişisel olarak güvenliğimizi artırmak için araştırmamız gereken konular arasına girdi. İnternet üzerinde yaptığımız her türlü araştırma ve web site ziyareti kayıt altına alınıyor bu bir...
  • Nasıl pasaport alınır ? detaylı anlatım 2021 5 December 2020
    Dünyanın başına gelmeyen olayın kalmadığı 2020 yılının son ayındayız. Hastalıklar, doğal afetler, ölümler, patlamalar, çatlamalar envai çeşit sıkıntıyla yüzleştik, umarım 2021 yılı daha hurulu ve mutlu geçer tüm dünya ve bizim için. 2020 yılının son ayına girdiğimiz şu günlerde uzun süredir aklımda olan bir eylemi gerçekleştirdim ve pasaport aldım. Pasaport alırken yapılacak işlemleri ve pasaport...
  • Pythonanywhere üzerinde selenium kullanımı 5 November 2020
    Python üzerinde veri kazıma yapmak isterseniz eğer muhakkak ismini duyup araştırmışsınızdır selenium modülünü. Selenium modülü ile kullanıcı taklit edilecek web sitesi üzerinde testler oluşturabilir ya da veri kazıma işlemleri yapabilirsiniz. Peki bu işlemleri herhangi bir ekrana sahip olmayan uzak sunucu üzerinde yapmak istersek nasıl gerçekleştireceğiz ? Hadi başlayalım. [baglanti_kare] [baglanti_kare][space] Python selenium modülü nedir ?...
  • Polylang eklentisi nedir ? WordPress sitesine çoklu dil ekleme nasıl yapılır ? 29 October 2020
    Herkese merhaba, bir blog siteniz varsa ve sürekli yazılar yayınlayıp paylaşıyorsanız eğer bir süre sonra bu yazıları farklı diller içinde paylaşmak isteyebilirsiniz. Farklı dillerde yayın yaparak daha fazla kitelelere ulaşabilir ve Google adsense ya da farklı reklam gösterimlerini kullanarak daha fazla gelir elde edebilirsniz. Peki wordpress alt yapısı ile oluşturulmuş bir sitede çoklu dil eklemek...
  • HTTP Metodları nelerdir ? 26 October 2020
    Bugün ki yazımda, gün içinde sıklıkla kullandığımız fakat arkaplanına pek dikkat etmediğimiz web site isteklerine bakacağız. Bilgisayar başına geçtiğimizde gerek iş için olsun gerekse bir araştırma için olsun bir çok web sitesini ziyaret ediyoruz, bu ziyaretlerimiz sırasında site ile iletişim kurmamız gereken durumlarda meydana geliyor. Peki bu iletişimin nasıl olduğunu hiç merak ettiniz mi ?...

Archives

  • July 2021 (2)
  • April 2021 (1)
  • October 2020 (2)
  • September 2020 (1)
  • March 2020 (1)
  • February 2020 (4)
  • January 2020 (6)
  • December 2019 (5)
  • November 2019 (3)
  • September 2019 (1)
  • July 2019 (1)
  • April 2019 (1)
  • December 2018 (2)
  • November 2018 (2)
  • October 2018 (1)
  • September 2018 (1)
  • August 2018 (4)

Blog Stats

  • 22,921 hits

Blog İnformation

  • 22,921 Click

DMCA.com Protection Status

© 2022 Kenan YAMAN | Powered by Minimalist Blog WordPress Theme
Go to mobile version