Python – Boolean Operators and Conditions

Basic conditions in Python:

< (one less than the other)
> (one more than the other)
<= (one is less than or equal to the other)
>= (one is greater than or equal to the other)
!= (one is not equal to the other)
== (one is equal to the other)

Examples of using conditions:

print(5 > 4)
True #result

print(‘cat’==’dog’)
False #result

Continue reading →

Posted in Python (en) | Leave a comment

Python – branching structures (if else, if, ifelif statements)

The if statement (if) is used to set conditions (if so, then…), for example:

cat_say = ‘mew’
if cat_say = ‘mew’ of cat_say = ‘myavki’:
….print(‘Dear, cat! Here’s your food!’)

Important: when using if conditions, you need to write double equals and put a colon at the end of the expression to show the end of the condition; before the rest of the code related to the condition, and print is indented with a tab (or 4 spaces).

Continue reading →

Posted in Python (en) | Leave a comment

Python – using format in strings

Inside the string, we can specify both fixed text and part of the text defined by the format function, which will consist of separately specified sections:

print(“This cat has {0} kittens and a {1}”.format(2,”tail”))

Instead of using numbers inside curly braces, you can immediately set the value of the variable in them – a,b,c:

print(‘quantity: ({a}, {b}, {c})’.format(a=5,b=2,c=4))

Continue reading →

Posted in Python (en) | Leave a comment

Python – strings, string concatenation and repetition

To assign a string to a variable, enclose the test either in apostrophes ‘…’ or in double quotes “…”:

string=’I am a cat’
string=”I am a cat”

If the string contains an apostrophe (I’m), then the entire string must be enclosed in double quotes, and vice versa. If the string contains both an apostrophe and double quotes, then a backslash \ must be used to escape the characters.

Continue reading →

Posted in Python (en) | Leave a comment

Python – programming environment and additional programs

When you have installed Python, the question arises – how to start learning this language? Should I write commands through the console or do I need to install something else on the computer? There are many programming environments and solutions for Python, but for a beginner, it is preferable to choose from two:

  • if you are learning Python for scientific purposes, then download Anaconda from www.continuum.io/downloads – this environment already includes Python, as well as such useful programs for programming and analytics as Spyder, Jupyter, IPython, R and others.
  • you are learning Python for general development, then install the cool Sublime Text code editor from sublimetext.com; in this case, you will need to manually configure the Python interpreter to run the program written in this editor.

Continue reading →

Posted in Python (en) | Leave a comment

Python – installation

To install Python on your computer, simply search Google for download python and follow the first link to www.python.org/downloads

The easiest way is to click on the bright button with the latest version of Python and then follow the installation process.

In addition to Python itself, you will probably need to install additional programs, which we will discuss next. When installing Python, remember that it is an interpretive programming language. If you write the code in notepad, it won’t work. And the code doesn’t need to be compiled like in C++. To run your code, you use either the built-in interpreter – Python 3.6.exe, or you can activate the interpreter in other text editors or programming environments.

 

Posted in Python (en) | Leave a comment

Python – forbidden variable names

To find out which names cannot be given to variables in Python, use the command:

import keyword
keyword.kwlist

For Python 3.6 this words are: Continue reading →

Posted in Python (en) | Leave a comment

Python – show result to user

When we write any program in any programming language, sooner or later we want the result of our programming to be shown to the user. For this we use the command:
print(…) must be lowercase
Continue reading →

Posted in Python (en) | Leave a comment

Python – Data Types (Objects)

In the Python programming language, there are three types objects (or data types – data type):

  • scalar (indivisible)
    • int (integers, integer, e.g. 5);
    • float (real number, numbers with a semicolon, for example: 5.5);
    • bool(true/false, true/false);
  • non-scalar (divisible)
    • str (string, string – all letters, text; everything that is not numbers).

Find out data type in Python:
type(…)

Example:
type(‘a’) – write a command

str – get the answer

Posted in Python (en) | Leave a comment

How to add Google Adsense in WordPress child theme

To insert ads into a child theme on an Adsense site: add the following code to function.php:

////////////////////////
///Google AdSense:
//
add_action('wp_head', 'wpse_43672_wp_head');
function wpse_43672_wp_head(){
    //Close PHP tags 
    ?>
<script data-ad-client="ca-pub-<publisher-numberic-code>" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <?php //Open PHP tags
}
////////////////////////

Don’t forget to replace the publisher’s numeric code (also removing the angle brackets around it).

p.s.
But in general it is more convenient to insert this code through a wordpress widget 🙂

Posted in Wordpress (en) | Leave a comment

Github: how to update a fork

Sometimes you fork a turnip for every firefighter (they sometimes delete it; we know, they passed ..) and you forget about it. But they write something in it, update it – you need to update yours too. The easiest way to do this is through the web interface:

  1. in your fork click Compare
  2. change the base (base) turnip to your fork
  3. click compare across forks
  4. change the head turnip to the original, from where we update
  5. create a pull request and merge!

You can do it through bash, but I have it on a virtual machine and I’m too lazy to go there, in order to make a turnip update 🙂 There are also softins that do this themselves, but somehow I don’t want to litter the computer with them.

I will be glad to your comments!

Posted in Git (en) | Leave a comment

Storing binaries on GitHub

I’ll tell you what to do if you are forced to store binaries on github. The problem is that they often do not start when Windows downloads from there with a .zip archive (link like https://github.com/[user]/[repo] /main.zip ). To solve this problem, you need to create a .gitattributes file inside, where you specify that git treats everything inside the turnip as binaries and does not put down BOMs (thanks to Serg Bloim for the tip). I do like this:

  1. create a private repository
  2. create such file in it .gitattributes
  3. inside file:
    * binary
  4. we throw binaries there through the web panel
  5. make the turnip public
Posted in Git (en) | Leave a comment

GitHub: How to clone a specific branch

If you’re just getting started with GitHub and using the web interface or GitHub Desktop, doing something as simple as cloning a specific branch of a repository can be quite a challenge. You can do this with Git Bash:

git clone git://github.com/<user>/<repo>.git
cd <repo>
git checkout <branch>/<name>
Posted in Git (en) | Leave a comment

Git – exclude file for local repository

This is not taught in school (note to yourself). To calmly work with a fake turnip locally, without hurting your wounds .. Go to the git folder and look for the “exclude” file there:

\.git\info\exclude

we write paths there, for example:
../../xxx/
../../yyy.sh

Posted in Git (en) | Leave a comment

Github: learning to work with a fork correctly

Sooner or later in the life of every mmm … Malthusian, let’s say .. there comes a moment when you need to learn how to work with the Git like a human being. In particular, engage in gardening – grow branches, graft them, cut them, and so on.

Well, I’m an amateur gardener and always pushed everything into a master. I drove a tank to the store for bread, so to speak.

But the time has come when it is important that the shoots grow in the right direction … Let’s say we made a fork (on the github website, click the button on the top right) and ..

Continue reading →

Posted in Git (en) | Leave a comment

WinMerge + Git = mergetool

I have been using the wonderful WinMerge tool for a long time, and I wish you the same. And now it’s time to merge conflicts on the git .. and the built-in tools or any alternative Git GUI turned out to be very buggy (tested a dozen) for exactly what I need. As a result, it turned out to be cheap and cheerful to check everything in WinMerge.

To use it, in a file C:\Users\<user>\.gitconfig add:

Continue reading →

Posted in Git (en) | Leave a comment

The unauthenticated git protocol on port 9418 is no longer supported

Found out that git pull stopped working today. Gives an error message:

The unauthenticated git protocol on port 9418 is no longer supported

Solution

First, let’s check where our git is knocking:

git remote -v

If you see the error indicated in the title of this post, then it is knocking on an outdated protocol git://

Now you need to switch to ssh://, https://, or git@github.com. So we write something like:

git remote set-url origin https://github.com/igroglaz/Tangaria.git

Well, only naturally instead of igroglaz and Tangaria – we indicate your turnip 🙂 That’s it, now everything should work. If it doesn’t work, check
Continue reading →

Posted in Git (en) | Leave a comment