Tigutor's blog

By Tigutor, 6 years ago, In English

In this short article, I want to introduce you Python and provide some basic steps to start learning.
First of all, consider the advantages of Python:
Crossflatformed, easy-to-read, popular, contains lots of methods to make web-apps, games(include Android) and, of course, you can do Python for a living, Python-developers are needed to work in Google, Yandex etc.
The main disadvantage of this language is speed. If your project or program requires fast implementation, you have to use C++, C or other fast languages.

After this introduction, you might imagine how it's easy to work in a big company using only Python — of course, it's not true, you should study lots of other things in Computer Science, but Python provides to every person methods to complete their own projects.

Now, consider some tricks which we can use in competitive programming to decrease the time of making your program
1. If your task requires repeat string n times, you don't have to use cycles like "for" or "while", you may only write:

 s = n * s

In this case, if n = 5 and s = "ab", the result of the program will be:

s = "ababababab"

Quite easier than other languages, isn't it?
2. Consider case if you need to replace two variables. Quite simple in every language, isn't it?
For example swap() function in C++. But what if you need to replace 3 or four variables? To make a, b, c, d equal to b, c, d, a.
Quite difficult in C++, but in Python just write:

a, b, c, d = b, c, d, a

That's all!
So, if a was 1, b was 2, c was 3, d was 4 then after this code it will be 2, 3, 4, 1 respectively.

Hope, now you're interested in Python!
Now you can download IDE from https://www.python.org/getit/ and try to complete your first program using such textbooks:
https://drive.google.com/file/d/0B2Y-n6IlHYliSXZxMk0xT0NSY1E/preview
In Russian this one: https://pythonworld.ru/samouchitel-python

I hope I made you interested in Python because I am going to make such posts every week, consider some interesting tasks and provide useful books or notes.
See you soon :)

  • Vote: I like it
  • -42
  • Vote: I do not like it

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Tigutor (previous revision, new revision, compare).

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Tigutor (previous revision, new revision, compare).

»
6 years ago, # |
Rev. 2   Vote: I like it +9 Vote: I do not like it

But what if you need to replace 3 or four variables? To make a, b, c, d equal to b, c, d, a. Quite difficult in C++

How difficult can it get from C++11?

tie(a, b, c, d) = make_tuple(b, c, d, a);

Try it out.

»
6 years ago, # |
Rev. 5   Vote: I like it +9 Vote: I do not like it

If your task requires repeat string n times

From Java 11, see this.

For C++, there is something called the fill constructor for repeating characters. I don't know a neat one-liner solution for repeating strings in C++ though.

There you go! Python's not very great after all.