Differences C # engineers felt when learning python for the first time

Hi, this is Muscle Training Clinical Engineering Engineer ken.

This is my first post on Qiita.

I usually use C # to develop medical systems. I started learning python because I wanted to focus on machine learning as well.

Learning is about the same as going around Progate's python course, but I will briefly summarize the differences from C # such as how to write.

For those who usually use C #, C ++, and VB and want to learn python from now on, I think that learning will progress if you know the difference between the two in advance.

A simple difference between C # and python in terms of code

No need for a semicolon at the end of a sentence

C#


Console.WriteLine("Hello C#");  //Be sure to end the statement with a semicolon

python


print("Hello python")

** Not required if the semicolon at the end of the statement is python. ** ** I wasn't used to it when I was using a language like C # that usually required a semicolon.

Variables do not need to be typed

C#


string[] animals = {"dog","cat"};   //All variables specify type

python


animals = ["dog","cat"]

** Python is a "dynamically typed language" and you don't have to specify the data type when declaring variables. ** **

I also feel that it seems easy to write code.

** By the way, python does not specify the type in the return value and arguments of the function. ** **

No need for braces, indentation affects code

C#


foreach(string animal in animals)
  {
    Console.WriteLine(animal);
  }

python


for animal in animals:
    print(animal)

Processing to output the contents of the array in the code If you look at (foreach in C #, for part in python), you can see it. ** python distinguishes post-conditional processing by: (colon) and indentation. ** ** The same applies to if statements.

It's also interesting that the presence or absence of indentation affects the operation. With this, anyone can write it so that it is easy to read.

List elements can be of any type

C#


string[] animals = {"dog","cat"};   //All variables specify type

python


animals = ["dog","cat",1,2]

A list is an array in C #. ** It is a feature that C # does not have that you can mix character strings, numeric types, etc. into one list element. ** **

By the way, in python, the process of extracting the contents of the array is described as for. The process is different from the C # for statement. This area may be confusing.

Summary

The above is a brief summary of the differences from other languages (C #) that I first felt learning about python. The following is a summary of the differences in the code so far. The output will be the same.

C#


using System;   //Namespace specification

namespace test  //Namespace declaration
{
    public class Hello //Class declaration
    {
        public static void Main() //Method
        {
        
            Console.WriteLine("Hello C#");  //Be sure to end the statement with a semicolon
        
            string[] animals = {"dog","cat"};   //All variables specify type
        
            foreach(string animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
    }
}

Output result


Hello C#
dog
cat

For python

python


print("Hello python")

animals = ["dog","cat"]

for animal in animals:
    print(animal)

Output result


Hello python
dog
cat

As you can see from the code, C # tends to be long because it describes details such as variable typing. On the other hand, python is very clean.

Not only python but also dynamically typed languages can be written simply, so I felt that it was suitable for high-speed development.

In the future, I will work on simple data analysis using python. Thank you for reading.

We also have a Personal blog, so please do not hesitate to contact us.

Recommended Posts

Differences C # engineers felt when learning python for the first time
See python for the first time
MongoDB for the first time in Python
I tried python programming for the first time.
A useful note when using Python for the first time in a while
I tried Python on Mac for the first time.
I tried python on heroku for the first time
Kaguru for the first time
If you're learning Linux for the first time, do this!
[For self-learning] Go2 for the first time
Start Django for the first time
What kind of environment should people who are learning Python for the first time build?
I tried tensorflow for the first time
Python Master RTA for the time being
Let's try Linux for the first time
[Python] [Machine learning] Beginners without any knowledge try machine learning for the time being
Impressions and memorandums when working with VS code for the first time
Since I'm free, the front-end engineer tried Python (v3.7.5) for the first time.
First time python
First time python
I tried using scrapy for the first time
How to use MkDocs for the first time
The story of low learning costs for Python
Upgrade the Azure Machine Learning SDK for Python
Use logger with Python for the time being
[Note] Deploying Azure Functions for the first time
I tried Mind Meld for the first time
First deep learning in C #-Imitating implementation in Python-
Try posting to Qiita for the first time
Looking back on the machine learning competition that I worked on for the first time
GTUG Girls + PyLadiesTokyo Meetup I went to machine learning for the first time
Import audit.log into Splunk and check the behavior when Splunk is started for the first time
The first step of machine learning ~ For those who want to implement with python ~
Run with CentOS7 + Apache2.4 + Python3.6 for the time being
[Python] Measures and displays the time required for processing
Register a task in cron for the first time
For the first time, I learned about Unix (Linux).
I felt that I ported the Python code to C ++ 98.
AI Gaming I tried it for the first time
Introduction to Deep Learning for the first time (Chainer) Japanese character recognition Chapter 1 [Environment construction]
The result of Java engineers learning machine learning in Python www
Summary of stumbling blocks in Django for the first time
[Understand in the shortest time] Python basics for data analysis
Introducing yourself at Qiita for the first time (test post)
I tried the Google Cloud Vision API for the first time
[Introduction to Reinforcement Learning] Reinforcement learning to try moving for the time being
Learning flow for Python beginners
Python learning plan for AI learning
Checkio's recommendation for learning Python
Code that I wish I had remembered when I participated in AtCoder for the first time (Reflection 1 for the next time)
The story of releasing a Python text check tool on GitHub x CircleCI for the first time
Introduction to Deep Learning for the first time (Chainer) Japanese character recognition Chapter 3 [Character recognition using a model]
The story of returning to the front line for the first time in 5 years and refactoring Python Django
What I learned by writing a Python Pull Request for the first time in my life
Understanding the python class Struggle (1) Let's move it for the time being
Let's touch Google's Vision API from Python for the time being
First aid when EditWithIdle disappears from the Windwos Python right-click menu
Try using FireBase Cloud Firestore in Python for the time being
"Cython" tutorial to make Python explosive: When C ++ code depends on the library. First of all, CMake.
Introduction to Deep Learning for the first time (Chainer) Japanese character recognition Chapter 2 [Model generation by machine learning]
Check the behavior when assigning Python