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.
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.
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. ** **
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.
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.
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.